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) 方法產生的 是 MethodCallExpression ,代表 Skip<TSource>(IQueryable<TSource>, Int32) 呼叫本身為一個構造化的泛型方法。 接著將 傳遞MethodCallExpression給CreateQuery(Expression)IQueryProvider由參數Provider性質source所表示的方法。
執行代表呼叫 Skip<TSource>(IQueryable<TSource>, Int32) 的表達式樹所產生的查詢行為,取決於參數型別 source 的實作。 預期行為是跳過 的source前幾個count元素,回傳剩餘的元素。