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 給以 CreateQuery(Expression) 參數的屬性所表示的方法 IQueryProvider Provider sourceIt 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) 取決於參數類型的實作為 sourceThe 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. 預期的行為是它會略過中的第一個 count 元素 source ,並傳回其餘的元素。The expected behavior is that it skips the first count elements in source and returns the remaining elements.

適用於