Queryable.Take(IQueryable<TSource>, Int32) Queryable.Take(IQueryable<TSource>, Int32) Queryable.Take(IQueryable<TSource>, Int32) Queryable.Take(IQueryable<TSource>, Int32) Method

定義

シーケンスの先頭から指定された数の連続する要素を返します。Returns a specified number of contiguous elements from the start of a sequence.

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

型パラメーター

TSource

source の要素の型。The type of the elements of source.

パラメーター

source
IQueryable<TSource>

要素を返すシーケンス。The sequence to return elements from.

count
Int32 Int32 Int32 Int32

返す要素数。The number of elements to return.

戻り値

IQueryable<TSource>

IQueryable<T>の先頭から要素の指定した数を格納しているsourceします。An IQueryable<T> that contains the specified number of elements from the start of source.

例外

次のコード例は、使用する方法を示しますTake<TSource>(IQueryable<TSource>, Int32)をシーケンスの先頭から要素を返します。The following code example demonstrates how to use Take<TSource>(IQueryable<TSource>, Int32) to return elements from the start of a sequence.

int[] grades = { 59, 82, 70, 56, 92, 98, 85 };

// Sort the grades in descending order and take the first three.
IEnumerable<int> topThreeGrades =
    grades.AsQueryable().OrderByDescending(grade => grade).Take(3);

Console.WriteLine("The top three grades are:");
foreach (int grade in topThreeGrades)
    Console.WriteLine(grade);

/*
    This code produces the following output:

    The top three grades are:
    98
    92
    85
*/

Dim grades() As Integer = {59, 82, 70, 56, 92, 98, 85}

' Sort the grades in descending order and take the first three.
Dim topThreeGrades = _
    grades.AsQueryable().OrderByDescending(Function(grade) grade).Take(3)

Dim output As New System.Text.StringBuilder
output.AppendLine("The top three grades are:")
For Each grade As Integer In topThreeGrades
    output.AppendLine(grade)
Next

' Display the output.
MsgBox(output.ToString())

' This code produces the following output:

' The top three grades are:
' 98
' 92
' 85

注釈

Take<TSource>(IQueryable<TSource>, Int32)メソッドを生成、MethodCallExpression呼び出しを表すTake<TSource>(IQueryable<TSource>, Int32)として構築されたジェネリック メソッド自体。The Take<TSource>(IQueryable<TSource>, Int32) method generates a MethodCallExpression that represents calling Take<TSource>(IQueryable<TSource>, Int32) itself as a constructed generic method. これは、後、渡します、MethodCallExpressionCreateQuery(Expression)のメソッド、IQueryProviderによって表される、Providerのプロパティ、sourceパラメーター。It then passes the MethodCallExpression to the CreateQuery(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

呼び出し元を表す式ツリーを実行した結果として発生するクエリの動作Take<TSource>(IQueryable<TSource>, Int32)の型の実装によって異なります、sourceパラメーター。The query behavior that occurs as a result of executing an expression tree that represents calling Take<TSource>(IQueryable<TSource>, Int32) depends on the implementation of the type of the source parameter. 想定される動作は、最初のかかるcountの先頭から要素sourceします。The expected behavior is that it takes the first count elements from the start of source.

適用対象