Queryable.ElementAt メソッド

定義

オーバーロード

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

シーケンス内の指定されたインデックス位置にある要素を返します。

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

シーケンス内の指定されたインデックス位置にある要素を返します。

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

シーケンス内の指定されたインデックス位置にある要素を返します。

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)

シーケンス内の指定されたインデックス位置にある要素を返します。

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 内の指定した位置にある要素。

例外

sourcenullです。

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) 自体を表す a を生成します。 次に、パラメーターのMethodCallExpressionExecute<TResult>(Expression)プロパティsourceで表されるメソッドIQueryProviderProvider渡します。

呼び出し ElementAt<TSource>(IQueryable<TSource>, Int32) を表す式ツリーを実行した結果として発生するクエリ動作は、パラメーターの型の source 実装によって異なります。 期待される動作は、次の位置index``sourceにある項目を返します。

適用対象