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 元素,並傳回其餘專案。

適用於