Enumerable.Skip<TSource>(IEnumerable<TSource>, Int32) メソッド
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
シーケンス内の指定された数の要素をバイパスし、残りの要素を返します。
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static System::Collections::Generic::IEnumerable<TSource> ^ Skip(System::Collections::Generic::IEnumerable<TSource> ^ source, int count);
public static System.Collections.Generic.IEnumerable<TSource> Skip<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, int count);
static member Skip : seq<'Source> * int -> seq<'Source>
<Extension()>
Public Function Skip(Of TSource) (source As IEnumerable(Of TSource), count As Integer) As IEnumerable(Of TSource)
- TSource
source
の要素の型。
- source
- IEnumerable<TSource>
返される要素が含まれる IEnumerable<T>。
- count
- Int32
残りの要素を返す前にスキップする要素の数。
入力シーケンスで指定されたインデックスの後に出現する要素を含む IEnumerable<T>。
source
は null
です。
次のコード例では、 を使用 Skip して配列内の指定された数の要素をスキップし、残りの要素を返す方法を示します。
int[] grades = { 59, 82, 70, 56, 92, 98, 85 };
Console.WriteLine("All grades except the first three:");
foreach (int grade in grades.Skip(3))
{
Console.WriteLine(grade);
}
/*
This code produces the following output:
All grades except the first three:
56
92
98
85
*/
' Create an array of integers that represent grades.
Dim grades() As Integer = {59, 82, 70, 56, 92, 98, 85}
' Sort the numbers in descending order and
' get all but the first (largest) three numbers.
Dim skippedGrades As IEnumerable(Of Integer) =
grades _
.Skip(3)
' Display the results.
Dim output As New System.Text.StringBuilder("All grades except the first three are:" & vbCrLf)
For Each grade As Integer In skippedGrades
output.AppendLine(grade)
Next
Console.WriteLine(output.ToString())
' This code produces the following output:
'
' All grades except the first three are:
' 56
' 92
' 98
' 85
このメソッドは、遅延実行を使用して実装されます。 即時戻り値は、アクションの実行に必要なすべての情報を格納する オブジェクトです。 このメソッドで表されるクエリは、オブジェクトがメソッドを直接呼び出GetEnumerator
すか、C# または For Each
Visual Basic で を使用foreach
して列挙されるまで実行されません。
が要素よりcount
少ない場合source
は、空IEnumerable<T>の が返されます。 が 0 以下の場合 count
、 のすべての要素 source
が生成されます。
Takeメソッドと Skip メソッドは機能補完です。 コレクション シーケンス coll
と整数 n
を指定すると、 の結果 coll.Take(n)
を連結すると、 と coll.Skip(n)
同じシーケンス coll
が生成されます。
Visual Basic クエリ式の構文では、 句は Skip
の Skip呼び出しに変換されます。
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。