Enumerable.SkipWhile メソッド

定義

指定された条件が満たされる限り、シーケンスの要素をバイパスした後、残りの要素を返します。

オーバーロード

SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

指定された条件が満たされる限り、シーケンスの要素をバイパスした後、残りの要素を返します。

SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource,Int32,Boolean>)

指定された条件が満たされる限り、シーケンスの要素をバイパスした後、残りの要素を返します。 要素のインデックスは、述語関数のロジックで使用されます。

SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)

指定された条件が満たされる限り、シーケンスの要素をバイパスした後、残りの要素を返します。

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

型パラメーター

TSource

source の要素の型。

パラメーター

source
IEnumerable<TSource>

返される要素が含まれる IEnumerable<T>

predicate
Func<TSource,Boolean>

各要素が条件を満たしているかどうかをテストする関数。

戻り値

IEnumerable<TSource>

predicate で指定されたテストに合格しない連続する最初の要素から入力シーケンスの要素を含む IEnumerable<T>

例外

source または predicatenull です。

次のコード例では、条件が true である限り、 を使用 SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>) して配列の要素をスキップする方法を示します。

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

IEnumerable<int> lowerGrades =
    grades
    .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
*/
' Create an array of integers that represent grades.
Dim grades() As Integer = {59, 82, 70, 56, 92, 98, 85}

' Sort the grades in descending order and
' get all grades greater less than 80.
Dim lowerGrades As IEnumerable(Of Integer) =
grades _
.OrderByDescending(Function(grade) grade) _
.SkipWhile(Function(grade) grade >= 80)

' Display the results.
Dim output As New System.Text.StringBuilder("All grades below 80:" & vbCrLf)
For Each grade As Integer In lowerGrades
    output.AppendLine(grade)
Next
Console.WriteLine(output.ToString())

' This code produces the following output:
'
' All grades below 80:
' 70
' 59
' 56

注釈

メソッドは SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>) 、遅延実行を使用して実装されます。 即時戻り値は、アクションの実行に必要なすべての情報を格納する オブジェクトです。 このメソッドで表されるクエリは、オブジェクトがメソッドを直接呼び出GetEnumeratorすか、C# または For Each Visual Basic で を使用foreachして列挙されるまで実行されません。

このメソッドは、 を使用して の source 各要素を predicate テストし、結果が の場合は true要素をスキップします。 述語関数が 要素に対してを返 false した後、その要素と 内の source 残りの要素が生成され、 の predicate呼び出しはそれ以上ありません。

シーケンス内のすべての要素に 対して を返trueす場合predicateは、空IEnumerable<T>の が返されます。

TakeWhileメソッドと SkipWhile メソッドは機能補完です。 コレクション シーケンス coll と純粋関数 pを指定すると、 の結果 coll.TakeWhile(p) を連結すると、 と coll.SkipWhile(p) 同じシーケンス collが生成されます。

Visual Basic クエリ式の構文では、 句は Skip WhileSkipWhile呼び出しに変換されます。

こちらもご覧ください

適用対象

SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource,Int32,Boolean>)

指定された条件が満たされる限り、シーケンスの要素をバイパスした後、残りの要素を返します。 要素のインデックスは、述語関数のロジックで使用されます。

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

型パラメーター

TSource

source の要素の型。

パラメーター

source
IEnumerable<TSource>

返される要素が含まれる IEnumerable<T>

predicate
Func<TSource,Int32,Boolean>

各ソース要素が条件に当てはまるかどうかをテストする関数。この関数の 2 つ目のパラメーターは、ソース要素のインデックスを表します。

戻り値

IEnumerable<TSource>

predicate で指定されたテストに合格しない連続する最初の要素から入力シーケンスの要素を含む IEnumerable<T>

例外

source または predicatenull です。

次のコード例では、要素のインデックスに依存する条件が true である限り、 を使用 SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource,Int32,Boolean>) して配列の要素をスキップする方法を示します。

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

IEnumerable<int> query =
    amounts.SkipWhile((amount, index) => amount > index * 1000);

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

/*
 This code produces the following output:

 4000
 1500
 5500
*/
' Create an array of integers.
Dim amounts() As Integer =
{5000, 2500, 9000, 8000, 6500, 4000, 1500, 5500}

' Skip items in the array whose value is greater than
' the item's index times 1000; get the remaining items.
Dim query As IEnumerable(Of Integer) =
amounts.SkipWhile(Function(amount, index) _
                      amount > index * 1000)

' Output the results.
Dim output As New System.Text.StringBuilder
For Each amount As Integer In query
    output.AppendLine(amount)
Next
Console.WriteLine(output.ToString())

' This code produces the following output:
'
' 4000
' 1500
' 5500

注釈

このメソッドは、遅延実行を使用して実装されます。 即時戻り値は、アクションの実行に必要なすべての情報を格納する オブジェクトです。 このメソッドで表されるクエリは、オブジェクトがメソッドを直接呼び出GetEnumeratorすか、C# または For Each Visual Basic で を使用foreachして列挙されるまで実行されません。

メソッドは SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource,Int32,Boolean>) を使用して の source 各要素を predicate テストし、結果が の場合は true要素をスキップします。 述語関数が 要素に対してを返 false した後、その要素と 内の source 残りの要素が生成され、 の predicate呼び出しはそれ以上ありません。

シーケンス内のすべての要素に 対して を返trueす場合predicateは、空IEnumerable<T>の が返されます。

の最初の predicate 引数は、テストする要素を表します。 2 番目の引数は、 内 sourceの要素の 0 から始まるインデックスを表します。

TakeWhileメソッドと SkipWhile メソッドは機能補完です。 コレクション シーケンス coll と純粋関数 pを指定すると、 の結果 coll.TakeWhile(p) を連結すると、 と coll.SkipWhile(p) 同じシーケンス collが生成されます。

Visual Basic クエリ式の構文では、 句は Skip WhileSkipWhile呼び出しに変換されます。

こちらもご覧ください

適用対象