Queryable.SkipWhile Metoda

Definicja

Pomija elementy w sekwencji, o ile określony warunek jest spełniony, a następnie zwraca pozostałe elementy.

Przeciążenia

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

Pomija elementy w sekwencji, o ile określony warunek jest spełniony, a następnie zwraca pozostałe elementy.

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

Pomija elementy w sekwencji, o ile określony warunek jest spełniony, a następnie zwraca pozostałe elementy. Indeks elementu jest używany w logice funkcji predykatu.

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

Źródło:
Queryable.cs
Źródło:
Queryable.cs
Źródło:
Queryable.cs

Pomija elementy w sekwencji, o ile określony warunek jest spełniony, a następnie zwraca pozostałe elementy.

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)

Parametry typu

TSource

Typ elementów elementu source.

Parametry

source
IQueryable<TSource>

Element do IQueryable<T> zwracania elementów.

predicate
Expression<Func<TSource,Boolean>>

Funkcja testowania każdego elementu na stanie.

Zwraca

IQueryable<TSource>

Element IQueryable<T> , który zawiera elementy rozpoczynające się od source pierwszego elementu w serii liniowej, który nie przechodzi testu określonego przez predicate.

Wyjątki

source lub predicate to null.

Przykłady

W poniższym przykładzie kodu pokazano, jak pominąć SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) elementy tablicy, o ile warunek jest spełniony.

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

Uwagi

Ta metoda ma co najmniej jeden parametr typu Expression<TDelegate> , którego argument type jest jednym z Func<T,TResult> typów. W przypadku tych parametrów można przekazać wyrażenie lambda i zostanie skompilowane do elementu Expression<TDelegate>.

Metoda SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) generuje element MethodCallExpression , który reprezentuje wywołanie SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) siebie jako skonstruowaną metodę ogólną. Następnie przekazuje MethodCallExpression element do CreateQuery(Expression) metody reprezentowanej IQueryProvider przez Provider właściwość parametru source .

Zachowanie zapytania, które występuje w wyniku wykonania drzewa wyrażeń, które reprezentuje wywołanie SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) , zależy od implementacji typu parametru source . Oczekiwane zachowanie polega na tym, że dotyczy predicate każdego elementu, source dopóki nie znajdzie elementu, dla którego predicate zwraca wartość false. Ten element i wszystkie pozostałe elementy są zwracane.

Dotyczy

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

Źródło:
Queryable.cs
Źródło:
Queryable.cs
Źródło:
Queryable.cs

Pomija elementy w sekwencji, o ile określony warunek jest spełniony, a następnie zwraca pozostałe elementy. Indeks elementu jest używany w logice funkcji predykatu.

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)

Parametry typu

TSource

Typ elementów elementu source.

Parametry

source
IQueryable<TSource>

Element do IQueryable<T> zwracania elementów.

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

Funkcja do testowania każdego elementu dla warunku; drugi parametr tej funkcji reprezentuje indeks elementu źródłowego.

Zwraca

IQueryable<TSource>

Element IQueryable<T> , który zawiera elementy rozpoczynające się od source pierwszego elementu w serii liniowej, który nie przechodzi testu określonego przez predicate.

Wyjątki

source lub predicate to null.

Przykłady

W poniższym przykładzie kodu pokazano, jak pominąć SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) elementy tablicy, o ile warunek zależny od indeksu elementu jest spełniony.

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

Uwagi

Ta metoda ma co najmniej jeden parametr typu Expression<TDelegate> , którego argument type jest jednym z Func<T,TResult> typów. W przypadku tych parametrów można przekazać wyrażenie lambda i zostanie skompilowane do elementu Expression<TDelegate>.

Metoda SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) generuje element MethodCallExpression , który reprezentuje wywołanie SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) siebie jako skonstruowaną metodę ogólną. Następnie przekazuje MethodCallExpression element do CreateQuery(Expression) metody reprezentowanej IQueryProvider przez Provider właściwość parametru source .

Zachowanie zapytania, które występuje w wyniku wykonania drzewa wyrażeń, które reprezentuje wywołanie SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) , zależy od implementacji typu parametru source . Oczekiwane zachowanie polega na tym, że dotyczy predicate każdego elementu, source dopóki nie znajdzie elementu, dla którego predicate zwraca wartość false. Ten element i wszystkie pozostałe elementy są zwracane. Indeks każdego elementu źródłowego jest udostępniany jako drugi argument do predicate.

Dotyczy