Enumerable.Zip Metoda

Definicja

Przeciążenia

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

Stosuje określoną funkcję do odpowiednich elementów dwóch sekwencji, tworząc sekwencję wyników.

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

Tworzy sekwencję krotki z elementami z trzech określonych sekwencji.

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

Tworzy sekwencję krotki z elementami z dwóch określonych sekwencji.

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

Stosuje określoną funkcję do odpowiednich elementów dwóch sekwencji, tworząc sekwencję wyników.

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)

Parametry typu

TFirst

Typ elementów pierwszej sekwencji wejściowej.

TSecond

Typ elementów drugiej sekwencji wejściowej.

TResult

Typ elementów sekwencji wyników.

Parametry

first
IEnumerable<TFirst>

Pierwsza sekwencja do scalenia.

second
IEnumerable<TSecond>

Druga sekwencja do scalenia.

resultSelector
Func<TFirst,TSecond,TResult>

Funkcja określająca sposób scalania elementów z dwóch sekwencji.

Zwraca

IEnumerable<TResult>

Element IEnumerable<T> zawierający scalone elementy dwóch sekwencji wejściowych.

Wyjątki

first lub second ma wartość null.

Przykłady

W poniższym przykładzie kodu pokazano, jak używać Zip metody do scalania dwóch sekwencji.

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

Uwagi

Ta metoda jest implementowana za pomocą odroczonego wykonania. Bezpośrednio zwracana wartość jest obiektem, który przechowuje wszystkie informacje wymagane do wykonania akcji. Zapytanie reprezentowane przez tę metodę nie jest wykonywane, dopóki obiekt nie zostanie wyliczone przez wywołanie metody GetEnumerator bezpośrednio lub przy użyciu foreach języka C# lub For Each w Visual Basic.

Metoda scala każdy element pierwszej sekwencji z elementem, który ma ten sam indeks w drugiej sekwencji. Jeśli sekwencje nie mają tej samej liczby elementów, metoda scala sekwencje aż do końca jednego z nich. Jeśli na przykład jedna sekwencja ma trzy elementy, a druga ma cztery, sekwencja wyników będzie miała tylko trzy elementy.

Zobacz też

Dotyczy

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

Tworzy sekwencję krotki z elementami z trzech określonych sekwencji.

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

Parametry typu

TFirst

Typ elementów pierwszej sekwencji wejściowej.

TSecond

Typ elementów drugiej sekwencji wejściowej.

TThird

Typ elementów trzeciej sekwencji wejściowej.

Parametry

first
IEnumerable<TFirst>

Pierwsza sekwencja do scalenia.

second
IEnumerable<TSecond>

Druga sekwencja do scalenia.

third
IEnumerable<TThird>

Trzecia sekwencja do scalenia.

Zwraca

IEnumerable<ValueTuple<TFirst,TSecond,TThird>>

Sekwencja krotki z elementami pobranymi z pierwszej, drugiej i trzeciej sekwencji w tej kolejności.

Zobacz też

Dotyczy

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

Tworzy sekwencję krotki z elementami z dwóch określonych sekwencji.

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

Parametry typu

TFirst

Typ elementów pierwszej sekwencji wejściowej.

TSecond

Typ elementów drugiej sekwencji wejściowej.

Parametry

first
IEnumerable<TFirst>

Pierwsza sekwencja do scalenia.

second
IEnumerable<TSecond>

Druga sekwencja do scalenia.

Zwraca

IEnumerable<ValueTuple<TFirst,TSecond>>

Sekwencja krotki z elementami pobranymi z pierwszej i drugiej sekwencji w tej kolejności.

Zobacz też

Dotyczy