Sdílet prostřednictvím


Queryable.SkipWhile Metoda

Definice

Obchází prvky v sekvenci, pokud je zadaná podmínka pravdivá a vrátí zbývající prvky.

Přetížení

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

Obchází prvky v sekvenci, pokud je zadaná podmínka pravdivá a vrátí zbývající prvky.

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

Obchází prvky v sekvenci, pokud je zadaná podmínka pravdivá a vrátí zbývající prvky. Index elementu se používá v logice predikátové funkce.

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

Zdroj:
Queryable.cs
Zdroj:
Queryable.cs
Zdroj:
Queryable.cs
Zdroj:
Queryable.cs
Zdroj:
Queryable.cs

Obchází prvky v sekvenci, pokud je zadaná podmínka pravdivá a vrátí zbývající prvky.

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

Parametry typu

TSource

Typ prvků .source

Parametry

source
IQueryable<TSource>

Návrat IQueryable<T> prvků.

predicate
Expression<Func<TSource,Boolean>>

Funkce k otestování jednotlivých prvků pro podmínku.

Návraty

IQueryable<TSource>

Prvek IQueryable<T> , který obsahuje prvky počínaje source prvním prvkem lineární řady, která neprojde testem určeným predicate.

Atributy

Výjimky

source nebo predicate je null.

Příklady

Následující příklad kódu ukazuje, jak lze přeskočit SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) prvky pole, pokud je podmínka pravdivá.

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

Poznámky

Tato metoda má alespoň jeden parametr typu Expression<TDelegate> , jehož argument typu je jedním z Func<T,TResult> typů. Pro tyto parametry můžete předat výraz lambda a bude zkompilován do Expression<TDelegate>.

Metoda SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) vygeneruje MethodCallExpression , která představuje samotné volání SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) jako vytvořenou obecnou metodu. Pak předá MethodCallExpression metodu IQueryProviderCreateQuery(Expression) reprezentované Provider vlastností parametrusource.

Chování dotazu, ke kterému dochází v důsledku spuštění stromu výrazu, který představuje volání SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) , závisí na implementaci typu parametru source . Očekávané chování je, že se vztahuje predicate na každý prvek, source dokud nenajde prvek, pro který predicate vrátí hodnotu false. Vrátí se tento prvek a všechny zbývající prvky.

Platí pro

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

Zdroj:
Queryable.cs
Zdroj:
Queryable.cs
Zdroj:
Queryable.cs
Zdroj:
Queryable.cs
Zdroj:
Queryable.cs

Obchází prvky v sekvenci, pokud je zadaná podmínka pravdivá a vrátí zbývající prvky. Index elementu se používá v logice predikátové funkce.

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

Parametry typu

TSource

Typ prvků .source

Parametry

source
IQueryable<TSource>

Návrat IQueryable<T> prvků.

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

Funkce k otestování jednotlivých prvků pro podmínku; druhý parametr této funkce představuje index zdrojového prvku.

Návraty

IQueryable<TSource>

Prvek IQueryable<T> , který obsahuje prvky počínaje source prvním prvkem lineární řady, která neprojde testem určeným predicate.

Atributy

Výjimky

source nebo predicate je null.

Příklady

Následující příklad kódu ukazuje, jak lze přeskočit SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) prvky pole, pokud podmínka, která závisí na indexu elementu je 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

Poznámky

Tato metoda má alespoň jeden parametr typu Expression<TDelegate> , jehož argument typu je jedním z Func<T,TResult> typů. Pro tyto parametry můžete předat výraz lambda a bude zkompilován do Expression<TDelegate>.

Metoda SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) vygeneruje MethodCallExpression , která představuje samotné volání SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) jako vytvořenou obecnou metodu. Pak předá MethodCallExpression metodu IQueryProviderCreateQuery(Expression) reprezentované Provider vlastností parametrusource.

Chování dotazu, ke kterému dochází v důsledku spuštění stromu výrazu, který představuje volání SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) , závisí na implementaci typu parametru source . Očekávané chování je, že se vztahuje predicate na každý prvek, source dokud nenajde prvek, pro který predicate vrátí hodnotu false. Vrátí se tento prvek a všechny zbývající prvky. Index každého zdrojového prvku je poskytován jako druhý argument pro predicate.

Platí pro