Поделиться через


Queryable.Skip<TSource>(IQueryable<TSource>, Int32) Метод

Определение

Проходит указанное число элементов в последовательности, а затем возвращает оставшиеся элементы.

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);
[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> Skip<TSource>(this System.Linq.IQueryable<TSource> source, int count);
static member Skip : 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 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)

Параметры типа

TSource

Тип элементов source.

Параметры

source
IQueryable<TSource>

Возвращает IQueryable<T> элементы из.

count
Int32

Количество элементов, пропускаемых перед возвратом оставшихся элементов.

Возвращаемое значение

IQueryable<TSource>

Объект IQueryable<T> , содержащий элементы, возникающие после указанного индекса в входной последовательности.

Атрибуты

Исключения

source равно null.

Примеры

В следующем примере кода показано, как пропустить Skip<TSource>(IQueryable<TSource>, Int32) указанное количество элементов в отсортированного массиве и вернуть оставшиеся элементы.

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

Комментарии

Метод Skip<TSource>(IQueryable<TSource>, Int32) создает объект MethodCallExpression , представляющий Skip<TSource>(IQueryable<TSource>, Int32) себя как созданный универсальный метод. Затем он передает MethodCallExpressionCreateQuery(Expression) метод IQueryProvider метода, представленного Provider свойством source параметра.

Поведение запроса, возникающее в результате выполнения дерева выражений, представляющего вызов Skip<TSource>(IQueryable<TSource>, Int32) , зависит от реализации типа source параметра. Ожидаемое поведение заключается в том, что он пропускает первые count элементы source и возвращает оставшиеся элементы.

Применяется к