Enumerable.Zip 메서드

정의

오버로드

Zip<TFirst,TSecond,TResult>(IEnumerable<TFirst>, IEnumerable<TSecond>, Func<TFirst,TSecond,TResult>)

지정된 함수를 두 시퀀스의 해당 요소에 적용하여 결과 시퀀스를 만듭니다.

Zip<TFirst,TSecond,TThird>(IEnumerable<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>)

지정된 세 시퀀스의 요소를 사용하여 튜플 시퀀스를 생성합니다.

Zip<TFirst,TSecond>(IEnumerable<TFirst>, IEnumerable<TSecond>)

지정된 두 시퀀스의 요소를 사용하여 튜플 시퀀스를 생성합니다.

Zip<TFirst,TSecond,TResult>(IEnumerable<TFirst>, IEnumerable<TSecond>, Func<TFirst,TSecond,TResult>)

지정된 함수를 두 시퀀스의 해당 요소에 적용하여 결과 시퀀스를 만듭니다.

public:
generic <typename TFirst, typename TSecond, typename TResult>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<TResult> ^ Zip(System::Collections::Generic::IEnumerable<TFirst> ^ first, System::Collections::Generic::IEnumerable<TSecond> ^ second, Func<TFirst, TSecond, TResult> ^ resultSelector);
public static System.Collections.Generic.IEnumerable<TResult> Zip<TFirst,TSecond,TResult> (this System.Collections.Generic.IEnumerable<TFirst> first, System.Collections.Generic.IEnumerable<TSecond> second, Func<TFirst,TSecond,TResult> resultSelector);
static member Zip : seq<'First> * seq<'Second> * Func<'First, 'Second, 'Result> -> seq<'Result>
<Extension()>
Public Function Zip(Of TFirst, TSecond, TResult) (first As IEnumerable(Of TFirst), second As IEnumerable(Of TSecond), resultSelector As Func(Of TFirst, TSecond, TResult)) As IEnumerable(Of TResult)

형식 매개 변수

TFirst

첫 번째 입력 시퀀스 요소의 형식입니다.

TSecond

두 번째 입력 시퀀스 요소의 형식입니다.

TResult

결과 시퀀스 요소의 형식입니다.

매개 변수

first
IEnumerable<TFirst>

병합할 첫 번째 시퀀스입니다.

second
IEnumerable<TSecond>

병합할 두 번째 시퀀스입니다.

resultSelector
Func<TFirst,TSecond,TResult>

두 시퀀스의 요소를 병합하는 방법을 지정하는 함수입니다.

반환

IEnumerable<TResult>

두 입력 시퀀스의 병합된 요소가 들어 있는 IEnumerable<T>입니다.

예외

first 또는 secondnull인 경우

예제

다음 코드 예제를 사용 Zip 하는 방법에 설명 합니다 두 시퀀스를 병합 하는 방법입니다.

int[] numbers = { 1, 2, 3, 4 };
string[] words = { "one", "two", "three" };

var numbersAndWords = numbers.Zip(words, (first, second) => first + " " + second);

foreach (var item in numbersAndWords)
    Console.WriteLine(item);

// This code produces the following output:

// 1 one
// 2 two
// 3 three
Dim numbers() As Integer = {1, 2, 3, 4}
Dim words() As String = {"one", "two", "three"}
Dim numbersAndWords = numbers.Zip(words, Function(first, second) first & " " & second)

For Each item In numbersAndWords
    Console.WriteLine(item)
Next

' This code produces the following output:

' 1 one
' 2 two
' 3 three

설명

이 메서드는 지연 된 실행을 사용 하 여 구현 됩니다. 즉시 반환 값은 작업을 수행 하는 데 필요한 모든 정보를 저장 하는 개체입니다. 이 메서드가 나타내는 쿼리는 개체를 직접 호출 GetEnumerator 하거나 C# 또는 For Each Visual Basic에서 를 사용하여 foreach 개체를 열거할 때까지 실행되지 않습니다.

메서드는 첫 번째 시퀀스의 각 요소를 두 번째 시퀀스에서 동일한 인덱스가 있는 요소와 병합합니다. 시퀀스에 동일한 수의 요소가 없는 경우 메서드는 시퀀스가 해당 요소 중 하나의 끝에 도달할 때까지 시퀀스를 병합합니다. 예를 들어 한 시퀀스에 3개의 요소가 있고 다른 시퀀스에 4개의 요소가 있는 경우 결과 시퀀스에는 3개의 요소만 있습니다.

추가 정보

적용 대상

Zip<TFirst,TSecond,TThird>(IEnumerable<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>)

지정된 세 시퀀스의 요소를 사용하여 튜플 시퀀스를 생성합니다.

public:
generic <typename TFirst, typename TSecond, typename TThird>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<ValueTuple<TFirst, TSecond, TThird>> ^ Zip(System::Collections::Generic::IEnumerable<TFirst> ^ first, System::Collections::Generic::IEnumerable<TSecond> ^ second, System::Collections::Generic::IEnumerable<TThird> ^ third);
public static System.Collections.Generic.IEnumerable<(TFirst First, TSecond Second, TThird Third)> Zip<TFirst,TSecond,TThird> (this System.Collections.Generic.IEnumerable<TFirst> first, System.Collections.Generic.IEnumerable<TSecond> second, System.Collections.Generic.IEnumerable<TThird> third);
static member Zip : seq<'First> * seq<'Second> * seq<'hird> -> seq<ValueTuple<'First, 'Second, 'hird>>
<Extension()>
Public Function Zip(Of TFirst, TSecond, TThird) (first As IEnumerable(Of TFirst), second As IEnumerable(Of TSecond), third As IEnumerable(Of TThird)) As IEnumerable(Of ValueTuple(Of TFirst, TSecond, TThird))

형식 매개 변수

TFirst

첫 번째 입력 시퀀스 요소의 형식입니다.

TSecond

두 번째 입력 시퀀스 요소의 형식입니다.

TThird

세 번째 입력 시퀀스의 요소 형식입니다.

매개 변수

first
IEnumerable<TFirst>

병합할 첫 번째 시퀀스입니다.

second
IEnumerable<TSecond>

병합할 두 번째 시퀀스입니다.

third
IEnumerable<TThird>

병합할 세 번째 시퀀스입니다.

반환

IEnumerable<ValueTuple<TFirst,TSecond,TThird>>

첫 번째, 두 번째 및 세 번째 시퀀스에서 가져온 요소를 순서대로 포함하는 튜플 시퀀스입니다.

추가 정보

적용 대상

Zip<TFirst,TSecond>(IEnumerable<TFirst>, IEnumerable<TSecond>)

지정된 두 시퀀스의 요소를 사용하여 튜플 시퀀스를 생성합니다.

public:
generic <typename TFirst, typename TSecond>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<ValueTuple<TFirst, TSecond>> ^ Zip(System::Collections::Generic::IEnumerable<TFirst> ^ first, System::Collections::Generic::IEnumerable<TSecond> ^ second);
public static System.Collections.Generic.IEnumerable<(TFirst First, TSecond Second)> Zip<TFirst,TSecond> (this System.Collections.Generic.IEnumerable<TFirst> first, System.Collections.Generic.IEnumerable<TSecond> second);
static member Zip : seq<'First> * seq<'Second> -> seq<ValueTuple<'First, 'Second>>
<Extension()>
Public Function Zip(Of TFirst, TSecond) (first As IEnumerable(Of TFirst), second As IEnumerable(Of TSecond)) As IEnumerable(Of ValueTuple(Of TFirst, TSecond))

형식 매개 변수

TFirst

첫 번째 입력 시퀀스 요소의 형식입니다.

TSecond

두 번째 입력 시퀀스 요소의 형식입니다.

매개 변수

first
IEnumerable<TFirst>

병합할 첫 번째 시퀀스입니다.

second
IEnumerable<TSecond>

병합할 두 번째 시퀀스입니다.

반환

IEnumerable<ValueTuple<TFirst,TSecond>>

첫 번째 및 두 번째 시퀀스에서 가져온 요소를 순서대로 사용하는 튜플 시퀀스입니다.

추가 정보

적용 대상