Queryable.ElementAt 메서드

정의

오버로드

ElementAt<TSource>(IQueryable<TSource>, Index)

시퀀스에서 지정된 인덱스의 요소를 반환합니다.

ElementAt<TSource>(IQueryable<TSource>, Int32)

시퀀스에서 지정된 인덱스의 요소를 반환합니다.

ElementAt<TSource>(IQueryable<TSource>, Index)

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

시퀀스에서 지정된 인덱스의 요소를 반환합니다.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static TSource ElementAt(System::Linq::IQueryable<TSource> ^ source, Index index);
public static TSource ElementAt<TSource> (this System.Linq.IQueryable<TSource> source, Index index);
static member ElementAt : System.Linq.IQueryable<'Source> * Index -> 'Source
<Extension()>
Public Function ElementAt(Of TSource) (source As IQueryable(Of TSource), index As Index) As TSource

형식 매개 변수

TSource

source 요소의 형식입니다.

매개 변수

source
IQueryable<TSource>

요소를 반환할 IQueryable<T>입니다.

index
Index

검색할 요소의 인덱스로, 시작 또는 끝에서 가져옵니다.

반환

TSource

시퀀스의 지정된 위치에 있는 요소입니다 source .

예외

sourcenull입니다.

index 가 시퀀스의 범위를 벗어났습니다 source .

적용 대상

ElementAt<TSource>(IQueryable<TSource>, Int32)

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

시퀀스에서 지정된 인덱스의 요소를 반환합니다.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static TSource ElementAt(System::Linq::IQueryable<TSource> ^ source, int index);
public static TSource ElementAt<TSource> (this System.Linq.IQueryable<TSource> source, int index);
static member ElementAt : System.Linq.IQueryable<'Source> * int -> 'Source
<Extension()>
Public Function ElementAt(Of TSource) (source As IQueryable(Of TSource), index As Integer) As TSource

형식 매개 변수

TSource

source 요소의 형식입니다.

매개 변수

source
IQueryable<TSource>

요소를 반환할 IQueryable<T>입니다.

index
Int32

검색할 요소의 0부터 시작하는 인덱스입니다.

반환

TSource

source에서 지정된 위치의 요소입니다.

예외

source이(가) null인 경우

index가 0보다 작은 경우

예제

다음 코드 예제에서는 를 사용하여 ElementAt<TSource>(IQueryable<TSource>, Int32) 시퀀스의 특정 위치에 있는 요소를 반환하는 방법을 보여 줍니다.

string[] names = { "Hartono, Tommy", "Adams, Terry",
                   "Andersen, Henriette Thaulow",
                   "Hedlund, Magnus", "Ito, Shu" };

Random random = new Random(DateTime.Now.Millisecond);

string name =
    names.AsQueryable().ElementAt(random.Next(0, names.Length));

Console.WriteLine("The name chosen at random is '{0}'.", name);

/*
    This code produces the following sample output.
    Yours may be different due to the use of Random.

    The name chosen at random is 'Ito, Shu'.
*/
Dim names() As String = {"Hartono, Tommy", "Adams, Terry", _
                   "Andersen, Henriette Thaulow", _
                   "Hedlund, Magnus", "Ito, Shu"}

Dim rand As New Random(DateTime.Now.Millisecond)

Dim name As String = _
    names.AsQueryable().ElementAt(rand.Next(0, names.Length))

MsgBox(String.Format("The name chosen at random is '{0}'.", name))

' This code produces the following sample output.
' Yours may be different due to the use of Random.
'
' The name chosen at random is 'Ito, Shu'.

설명

메서드는 ElementAt<TSource>(IQueryable<TSource>, Int32)MethodCallExpression 생성된 제네릭 메서드로 자신을 호출 ElementAt<TSource>(IQueryable<TSource>, Int32) 하는 를 나타내는 을 생성합니다. 그런 다음 을 MethodCallExpression 매개 변수의 Execute<TResult>(Expression) 속성으로 나타내는 의 IQueryProvider 메서드에 Providersource 전달합니다.

호출 ElementAt<TSource>(IQueryable<TSource>, Int32) 을 나타내는 식 트리를 실행한 결과로 발생하는 쿼리 동작은 매개 변수 형식의 source 구현에 따라 달라집니다. 예상되는 동작은 의 위치에 indexsource있는 항목을 반환하는 것입니다.

적용 대상