Queryable.Skip<TSource>(IQueryable<TSource>, Int32) Metoda

Definicja

Pomija określoną liczbę elementów w sekwencji, a następnie zwraca pozostałe elementy.

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

Parametry typu

TSource

Typ elementów elementu source.

Parametry

source
IQueryable<TSource>

Element do IQueryable<T> zwracania elementów.

count
Int32

Liczba elementów do pominięcia przed zwróceniem pozostałych elementów.

Zwraca

IQueryable<TSource>

Element IQueryable<T> zawierający elementy, które występują po określonym indeksie w sekwencji danych wejściowych.

Wyjątki

source to null.

Przykłady

W poniższym przykładzie kodu pokazano, jak pominąć Skip<TSource>(IQueryable<TSource>, Int32) określoną liczbę elementów w posortowanej tablicy i zwrócić pozostałe elementy.

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

// Sort the grades in descending order and
// get all except the first three.
IEnumerable<int> lowerGrades =
    grades.AsQueryable().OrderByDescending(g => g).Skip(3);

Console.WriteLine("All grades except the top three are:");
foreach (int grade in lowerGrades)
    Console.WriteLine(grade);

/*
    This code produces the following output:

    All grades except the top three are:
    82
    70
    59
    56
*/
Dim grades() As Integer = {59, 82, 70, 56, 92, 98, 85}

' Sort the grades in descending order and
' get all except the first three.
Dim lowerGrades = grades.AsQueryable() _
    .OrderByDescending(Function(g) g) _
    .Skip(3)

Dim output As New System.Text.StringBuilder
output.AppendLine("All grades except the top three are:")
For Each grade As Integer In lowerGrades
    output.AppendLine(grade)
Next

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

' This code produces the following output:

' All grades except the top three are:
' 82
' 70
' 59
' 56

Uwagi

Metoda Skip<TSource>(IQueryable<TSource>, Int32) generuje element MethodCallExpression , który reprezentuje wywołanie Skip<TSource>(IQueryable<TSource>, Int32) siebie jako skonstruowaną metodę ogólną. Następnie przekazuje MethodCallExpression element do CreateQuery(Expression) metody reprezentowanej IQueryProvider przez Provider właściwość parametru source .

Zachowanie zapytania, które występuje w wyniku wykonania drzewa wyrażeń, które reprezentuje wywołanie Skip<TSource>(IQueryable<TSource>, Int32) , zależy od implementacji typu parametru source . Oczekiwane zachowanie polega na tym, że pomija pierwsze count elementy i source zwraca pozostałe elementy.

Dotyczy