Queryable.Skip<TSource>(IQueryable<TSource>, Int32) 方法

定义

跳过序列中指定数量的元素,然后返回剩余的元素。Bypasses a specified number of elements in a sequence and then returns the remaining elements.

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 的元素类型。The type of the elements of source.

参数

source
IQueryable<TSource>

要从中返回元素的 IQueryable<T>An IQueryable<T> to return elements from.

count
Int32

返回剩余元素前要跳过的元素数量。The number of elements to skip before returning the remaining elements.

返回

IQueryable<TSource>

一个 IQueryable<T>,包含输入序列中指定索引后出现的元素。An IQueryable<T> that contains elements that occur after the specified index in the input sequence.

异常

sourcenullsource is null.

示例

下面的代码示例演示如何使用 Skip<TSource>(IQueryable<TSource>, Int32) 跳过已排序数组中指定数目的元素,并返回剩余的元素。The following code example demonstrates how to use Skip<TSource>(IQueryable<TSource>, Int32) to skip a specified number of elements in a sorted array and return the remaining elements.

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) 本身。The Skip<TSource>(IQueryable<TSource>, Int32) method generates a MethodCallExpression that represents calling Skip<TSource>(IQueryable<TSource>, Int32) itself as a constructed generic method. 然后,它将 MethodCallExpression 传递到 IQueryProviderCreateQuery(Expression) 方法(由 source 参数的 Provider 属性表示)。It then passes the MethodCallExpression to the CreateQuery(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

因执行表示调用 Skip<TSource>(IQueryable<TSource>, Int32) 的表达式树而发生的查询行为取决于 source 参数类型的实现。The query behavior that occurs as a result of executing an expression tree that represents calling Skip<TSource>(IQueryable<TSource>, Int32) depends on the implementation of the type of the source parameter. 预期的行为是跳过 source 中的第一个 count 元素,并返回剩余的元素。The expected behavior is that it skips the first count elements in source and returns the remaining elements.

适用于