Enumerable.Skip<TSource>(IEnumerable<TSource>, Int32) 메서드

정의

시퀀스에서 지정된 개수의 요소를 바이패스한 다음 나머지 요소를 반환합니다.

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<TSource>

IEnumerable<T> 입력 시퀀스에서 지정된 인덱스 다음에 발생하는 요소를 포함하는 요소입니다.

예외

sourcenull입니다.

예제

다음 코드 예제에서는 배열에서 지정된 개수의 요소를 건너뛰고 나머지 요소를 반환하는 방법을 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#의 foreach 또는 Visual Basic For Each 사용하여 개체가 열거될 때까지 실행되지 않습니다.

요소보다 source 적은 수의 요소가 포함된 경우 countIEnumerable<T> 항목이 반환됩니다. 0보다 작거나 같으면 count 모든 요소가 source 생성됩니다.

Take 메서드는 Skip 기능 보완입니다. 컬렉션 시퀀스와 coll 정수가 지정되면 결과를 n 연결하고 coll.Take(n)coll.Skip(n).coll

Visual Basic 쿼리 식 구문에서 Skip 절은 Skip 호출로 변환됩니다.

적용 대상

추가 정보