Queryable.Skip<TSource>(IQueryable<TSource>, Int32) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
绕过序列中的指定数量的元素,然后返回其余元素。
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<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)生成一个表示调用Skip<TSource>(IQueryable<TSource>, Int32)自身为已构造泛型方法的一MethodCallExpression个方法。 然后,它将传递给MethodCallExpressionCreateQuery(Expression)由参数属性source表示Provider的方法IQueryProvider。
执行表示调用 Skip<TSource>(IQueryable<TSource>, Int32) 的表达式树导致的查询行为取决于参数类型的 source 实现。 预期行为是它跳过第source一个count元素并返回其余元素。