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>>)

如果指定的条件为 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>>)

如果指定的条件为 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参数提供。

适用于