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# 또는 For Each Visual Basic에서 를 사용하여 foreach 개체를 열거할 때까지 실행되지 않습니다.

보다 적은 count 요소가 포함된 경우 sourceIEnumerable<T> 가 반환됩니다. 가 0보다 작거나 같으면 countsource 모든 요소가 생성됩니다.

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

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

적용 대상

추가 정보