Enumerable.Skip(IEnumerable<TSource>, Int32) Enumerable.Skip(IEnumerable<TSource>, Int32) Enumerable.Skip(IEnumerable<TSource>, Int32) Enumerable.Skip(IEnumerable<TSource>, Int32) Method

定義

シーケンス内の指定された数の要素をバイパスし、残りの要素を返します。 Bypasses a specified number of elements in a sequence and then returns the remaining elements.

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

要素の型ソースします。 The type of the elements of source.

パラメーター
source
IEnumerable<TSource>

返される要素が含まれる IEnumerable<T> An IEnumerable<T> to return elements from.

count
Int32 Int32 Int32 Int32

残りの要素を返す前にスキップする要素の数。 The number of elements to skip before returning the remaining elements.

戻り値
IEnumerable<TSource>

入力シーケンスで指定されたインデックスの後に出現する要素を含む IEnumerable<T> An IEnumerable<T> that contains the elements that occur after the specified index in the input sequence.

例外

次のコード例は、使用する方法を示しますSkipを要素の並べ替え済み配列の指定した数をスキップし、残りの要素を返します。The following code example demonstrates how to use Skip to skip a specified number of elements in a sorted array and return the remaining elements.

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

IEnumerable<int> lowerGrades =
    grades.OrderByDescending(g => g).Skip(3);

Console.WriteLine("All grades except the top three are:");
foreach (int grade in lowerGrades)
{
    Console.WriteLine(grade);
}

/*
 This code produces the following output:

 All grades except the top three are:
 82
 70
 59
 56
*/

' 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 lowerGrades As IEnumerable(Of Integer) =
grades _
.OrderByDescending(Function(g) g) _
.Skip(3)

' Display the results.
Dim output As New System.Text.StringBuilder("All grades except the top three are:" & vbCrLf)
For Each grade As Integer In lowerGrades
    output.AppendLine(grade)
Next
MsgBox(output.ToString())

' This code produces the following output:
'
' All grades except the top three are:
' 82
' 70
' 59
' 56

注釈

このメソッドは、遅延実行を使用して実装されます。This method is implemented by using deferred execution. 即時の戻り値は、操作を実行するために必要なすべての情報を格納するオブジェクトです。The immediate return value is an object that stores all the information that is required to perform the action. か、呼び出すことによって、オブジェクトが列挙されるまで、このメソッドによって表されるクエリは実行されません、GetEnumeratorメソッドを使用して直接またはforeachVisual c# またはFor EachVisual Basic で。The query represented by this method is not executed until the object is enumerated either by calling its GetEnumerator method directly or by using foreach in Visual C# or For Each in Visual Basic.

場合source未満count要素、空IEnumerable<T>が返されます。If source contains fewer than count elements, an empty IEnumerable<T> is returned. 場合countがゼロのすべての要素に小さいsourceは返されます。If count is less than or equal to zero, all elements of source are yielded.

TakeSkipメソッドは、機能を補完します。The Take and Skip methods are functional complements. シーケンスの指定collおよび整数nの結果を連結coll.Take(n)coll.Skip(n)と同じシーケンスを生成collします。Given a sequence coll and an integer n, concatenating the results of coll.Take(n) and coll.Skip(n) yields the same sequence as coll.

Visual Basic のクエリ式の構文をSkip句がの呼び出しに変換されますSkipします。In Visual Basic query expression syntax, a Skip clause translates to an invocation of Skip.

適用対象

こちらもご覧ください