次の方法で共有


Queryable.Take メソッド

定義

オーバーロード

名前 説明
Take<TSource>(IQueryable<TSource>, Int32)

シーケンスの先頭から指定した数の連続する要素を返します。

Take<TSource>(IQueryable<TSource>, Range)

シーケンスから指定した連続する要素の範囲を返します。

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

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

シーケンスの先頭から指定した数の連続する要素を返します。

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);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
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>
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
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の要素の型。

パラメーター

source
IQueryable<TSource>

要素を返すシーケンス。

count
Int32

返す要素の数。

戻り値

IQueryable<TSource>

sourceの先頭から指定した数の要素を含むIQueryable<T>

属性

例外

sourcenullです。

次のコード例では、 Take<TSource>(IQueryable<TSource>, Int32) を使用してシーケンスの先頭から要素を返す方法を示します。

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) メソッドは、構築されたジェネリック メソッドとしての呼び出しTake<TSource>(IQueryable<TSource>, Int32)自体を表すMethodCallExpressionを生成します。 次に、source パラメーターのProvider プロパティで表されるIQueryProviderCreateQuery(Expression) メソッドにMethodCallExpressionを渡します。

呼び出し Take<TSource>(IQueryable<TSource>, Int32) を表す式ツリーを実行した結果として発生するクエリ動作は、 source パラメーターの型の実装によって異なります。 想定される動作は、sourceの先頭から最初のcount要素を受け取ります。

適用対象

Take<TSource>(IQueryable<TSource>, Range)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

シーケンスから指定した連続する要素の範囲を返します。

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IQueryable<TSource> ^ Take(System::Linq::IQueryable<TSource> ^ source, Range range);
public static System.Linq.IQueryable<TSource> Take<TSource>(this System.Linq.IQueryable<TSource> source, Range range);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static System.Linq.IQueryable<TSource> Take<TSource>(this System.Linq.IQueryable<TSource> source, Range range);
static member Take : System.Linq.IQueryable<'Source> * Range -> System.Linq.IQueryable<'Source>
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
static member Take : System.Linq.IQueryable<'Source> * Range -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function Take(Of TSource) (source As IQueryable(Of TSource), range As Range) As IQueryable(Of TSource)

型パラメーター

TSource

sourceの要素の型。

パラメーター

source
IQueryable<TSource>

要素を返すシーケンス。

range
Range

開始インデックスと終了インデックスを含む、返す要素の範囲。

戻り値

IQueryable<TSource>

source シーケンスの要素の指定したrangeを含むIQueryable<T>

属性

例外

sourcenullです。

適用対象