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);
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>,包含输入序列中指定索引后出现的元素。

例外

sourcenull

示例

下面的代码示例演示如何使用 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)它将 传递给 由 Provider 参数的 属性表示的 的 source 方法IQueryProvider

由于执行表示调用 Skip<TSource>(IQueryable<TSource>, Int32) 的表达式树而发生的查询行为取决于 参数类型的 source 实现。 预期的行为是,它会跳过 中的source第一个count元素,并返回剩余的元素。

适用于