Queryable.SkipWhile 方法

定義

只要指定的條件為 true,便略過序列中的項目,然後傳回其餘項目。

多載

SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

只要指定的條件為 true,便略過序列中的項目,然後傳回其餘項目。

SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>)

只要指定的條件為 true,便略過序列中的項目,然後傳回其餘項目。 項目的索引是用於述詞功能的邏輯中。

SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

來源:
Queryable.cs
來源:
Queryable.cs
來源:
Queryable.cs

只要指定的條件為 true,便略過序列中的項目,然後傳回其餘項目。

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IQueryable<TSource> ^ SkipWhile(System::Linq::IQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, bool> ^> ^ predicate);
public static System.Linq.IQueryable<TSource> SkipWhile<TSource> (this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,bool>> predicate);
static member SkipWhile : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, bool>> -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function SkipWhile(Of TSource) (source As IQueryable(Of TSource), predicate As Expression(Of Func(Of TSource, Boolean))) As IQueryable(Of TSource)

類型參數

TSource

source 項目的類型。

參數

source
IQueryable<TSource>

傳回項目的 IQueryable<T>

predicate
Expression<Func<TSource,Boolean>>

用來測試每個項目是否符合條件的函式。

傳回

IQueryable<TSource>

IQueryable<T>,其中包含的項目位於 source,而且是從沒有通過 predicate 所指定之測試的線性系列中第一個項目開始。

例外狀況

sourcepredicatenull

範例

下列程式代碼範例示範如何使用 SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) 來略過陣列的專案,只要條件為 true。

int[] grades = { 59, 82, 70, 56, 92, 98, 85 };

// Get all grades less than 80 by first
// sorting the grades in descending order and then
// taking all the grades after the first grade
// that is less than 80.
IEnumerable<int> lowerGrades =
    grades.AsQueryable()
    .OrderByDescending(grade => grade)
    .SkipWhile(grade => grade >= 80);

Console.WriteLine("All grades below 80:");
foreach (int grade in lowerGrades)
    Console.WriteLine(grade);

/*
    This code produces the following output:

    All grades below 80:
    70
    59
    56
*/
Dim grades() As Integer = {59, 82, 70, 56, 92, 98, 85}

' Get all grades less than 80 by first  sorting the grades 
' in descending order and then taking all the grades that 
' occur after the first grade that is less than 80.
Dim lowerGrades = grades.AsQueryable() _
    .OrderByDescending(Function(grade) grade) _
    .SkipWhile(Function(grade) grade >= 80)

Dim output As New System.Text.StringBuilder
output.AppendLine("All grades below 80:")
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 below 80:
' 70
' 59
' 56

備註

這個方法至少有一個類型 Expression<TDelegate> 參數,其類型自變數為其中一個 Func<T,TResult> 型別。 針對這些參數,您可以傳入 Lambda 運算式,並將它編譯為 Expression<TDelegate>

方法 SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) 會產生 , MethodCallExpression 表示 SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) 呼叫本身做為建構的泛型方法。 然後,它會將 傳遞MethodCallExpressionCreateQuery(Expression) 參數的 屬性所Provider表示的 source 方法IQueryProvider

執行表示呼叫 SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) 的表達式樹狀結構所產生的查詢行為,取決於參數類型的 source 實作。 預期的行為是它會套用 predicate 至 中的每個 source 元素,直到找到 predicate 傳回 false 的項目為止。 該元素和其餘項目都會傳回。

適用於

SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>)

來源:
Queryable.cs
來源:
Queryable.cs
來源:
Queryable.cs

只要指定的條件為 true,便略過序列中的項目,然後傳回其餘項目。 項目的索引是用於述詞功能的邏輯中。

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IQueryable<TSource> ^ SkipWhile(System::Linq::IQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, int, bool> ^> ^ predicate);
public static System.Linq.IQueryable<TSource> SkipWhile<TSource> (this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,int,bool>> predicate);
static member SkipWhile : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, int, bool>> -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function SkipWhile(Of TSource) (source As IQueryable(Of TSource), predicate As Expression(Of Func(Of TSource, Integer, Boolean))) As IQueryable(Of TSource)

類型參數

TSource

source 項目的類型。

參數

source
IQueryable<TSource>

傳回項目的 IQueryable<T>

predicate
Expression<Func<TSource,Int32,Boolean>>

用來測試各項目是否符合條件的函式;此函式的第二個參數代表來源項目的索引。

傳回

IQueryable<TSource>

IQueryable<T>,其中包含的項目位於 source,而且是從沒有通過 predicate 所指定之測試的線性系列中第一個項目開始。

例外狀況

sourcepredicatenull

範例

下列程式代碼範例示範如何使用 SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) 來略過陣列的專案,只要相依於專案的索引的條件為 true。

int[] amounts = { 5000, 2500, 9000, 8000,
                    6500, 4000, 1500, 5500 };

// Skip over amounts in the array until the first amount
// that is less than or equal to the product of its
// index in the array and 1000. Take the remaining items.
IEnumerable<int> query =
    amounts.AsQueryable()
    .SkipWhile((amount, index) => amount > index * 1000);

foreach (int amount in query)
    Console.WriteLine(amount);

/*
    This code produces the following output:

    4000
    1500
    5500
*/
Dim amounts() As Integer = {5000, 2500, 9000, 8000, _
                    6500, 4000, 1500, 5500}

' Skip over amounts in the array until the first amount
' that is less than or equal to the product of its
' index in the array and 1000. Take the remaining items.
Dim query = amounts.AsQueryable() _
    .SkipWhile(Function(amount, index) amount > index * 1000)

Dim output As New System.Text.StringBuilder
For Each amount As Integer In query
    output.AppendLine(amount)
Next

' Display the output.
MsgBox(output.ToString())

' This code produces the following output:

' 4000
' 1500
' 5500

備註

這個方法至少有一個類型 Expression<TDelegate> 參數,其類型自變數為其中一個 Func<T,TResult> 型別。 針對這些參數,您可以傳入 Lambda 運算式,並將它編譯為 Expression<TDelegate>

方法 SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) 會產生 , MethodCallExpression 表示 SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) 呼叫本身做為建構的泛型方法。 然後,它會將 傳遞MethodCallExpressionCreateQuery(Expression) 參數的 屬性所Provider表示的 source 方法IQueryProvider

執行表示呼叫 SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) 的表達式樹狀結構所產生的查詢行為,取決於參數類型的 source 實作。 預期的行為是它會套用 predicate 至 中的每個 source 元素,直到找到 predicate 傳回 false 的項目為止。 該元素和其餘項目都會傳回。 每個來源項目的索引會以 的第二個自變數 predicate的形式提供給 。

適用於