Queryable.Take Yöntem

Tanım

Aşırı Yüklemeler

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

Bir sıranın başlangıcından belirtilen sayıda bitişik öğe döndürür.

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

Bir diziden belirli bir bitişik öğe aralığını döndürür.

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

Kaynak:
Queryable.cs
Kaynak:
Queryable.cs
Kaynak:
Queryable.cs

Bir sıranın başlangıcından belirtilen sayıda bitişik öğe döndürür.

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)

Tür Parametreleri

TSource

öğelerinin sourcetürü.

Parametreler

source
IQueryable<TSource>

Öğelerinin döndürüleceği sıra.

count
Int32

Döndürülecek öğe sayısı.

Döndürülenler

IQueryable<TSource>

IQueryable<T> öğesinin başlangıcından sourceitibaren belirtilen sayıda öğeyi içeren bir .

Özel durumlar

source, null değeridir.

Örnekler

Aşağıdaki kod örneği, bir sıranın başlangıcından öğeleri döndürmek için nasıl kullanılacağını Take<TSource>(IQueryable<TSource>, Int32) gösterir.

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

Açıklamalar

yöntemi, Take<TSource>(IQueryable<TSource>, Int32) kendisini oluşturulan genel bir MethodCallExpression yöntem olarak çağırmayı Take<TSource>(IQueryable<TSource>, Int32) temsil eden bir oluşturur. Daha sonra parametresinin özelliği tarafından Provider temsil edilen yöntemine IQueryProvidersource iletirMethodCallExpression.CreateQuery(Expression)

Çağrıyı Take<TSource>(IQueryable<TSource>, Int32) temsil eden bir ifade ağacının yürütülmesi sonucunda oluşan sorgu davranışı, parametre türünün uygulanmasına source bağlıdır. Beklenen davranış, başından itibaren ilk count öğeleri almasıdır source.

Şunlara uygulanır

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

Kaynak:
Queryable.cs
Kaynak:
Queryable.cs
Kaynak:
Queryable.cs

Bir diziden belirli bir bitişik öğe aralığını döndürür.

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);
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)

Tür Parametreleri

TSource

öğelerinin sourcetürü.

Parametreler

source
IQueryable<TSource>

Öğelerinin döndürüleceği sıra.

range
Range

Başlangıçtan veya sonundan başlangıç ve bitiş dizinleri olan döndürülecek öğe aralığı.

Döndürülenler

IQueryable<TSource>

IQueryable<T> Diziden source belirtilen range öğeleri içeren bir.

Özel durumlar

source, null değeridir.

Şunlara uygulanır