Enumerable.Zip Yöntem

Tanım

Aşırı Yüklemeler

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

Belirtilen bir işlevi, iki sıranın karşılık gelen öğelerine uygular ve sonuçların bir dizisini üretir.Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.

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

Belirtilen iki dizideki öğeleri içeren bir tanımlama grubu sırası üretir.Produces a sequence of tuples with elements from the two specified sequences.

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

Belirtilen bir işlevi, iki sıranın karşılık gelen öğelerine uygular ve sonuçların bir dizisini üretir.Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.

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)

Tür Parametreleri

TFirst

İlk giriş dizisinin öğelerinin türü.The type of the elements of the first input sequence.

TSecond

İkinci giriş dizisinin öğelerinin türü.The type of the elements of the second input sequence.

TResult

Sonuç dizisinin öğelerinin türü.The type of the elements of the result sequence.

Parametreler

first
IEnumerable<TFirst>

Birleştirilecek ilk dizi.The first sequence to merge.

second
IEnumerable<TSecond>

Birleştirilecek ikinci sıra.The second sequence to merge.

resultSelector
Func<TFirst,TSecond,TResult>

İki diziden öğelerin nasıl birleştirilyapılacağını belirten bir işlev.A function that specifies how to merge the elements from the two sequences.

Döndürülenler

IEnumerable<TResult>

IEnumerable<T>İki giriş dizisinin birleştirilmiş öğelerini içeren bir.An IEnumerable<T> that contains merged elements of two input sequences.

Özel durumlar

first ya second da null .first or second is null.

Örnekler

Aşağıdaki kod örneği, Zip iki diziyi birleştirmek için yönteminin nasıl kullanılacağını gösterir.The following code example demonstrates how to use the Zip method to merge two sequences.

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

Açıklamalar

Bu yöntem ertelenmiş yürütme kullanılarak uygulanır.This method is implemented by using deferred execution. Anında dönüş değeri, eylemi gerçekleştirmek için gereken tüm bilgileri depolayan bir nesnedir.The immediate return value is an object that stores all the information that is required to perform the action. Bu yöntem tarafından temsil edilen sorgu, nesne GetEnumerator yöntemi doğrudan çağırarak ya da foreach Visual C# ' de veya Visual Basic kullanılarak numaralandırılana kadar yürütülmez For Each .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.

Yöntemi, ikinci dizide aynı dizine sahip olan bir öğesiyle ilk sıradaki her öğeyi birleştirir.The method merges each element of the first sequence with an element that has the same index in the second sequence. Diziler aynı sayıda öğeye sahip değilse, yöntemi bunlardan birinin sonuna ulaşana kadar dizileri birleştirir.If the sequences do not have the same number of elements, the method merges sequences until it reaches the end of one of them. Örneğin, bir dizide üç öğe varsa ve diğeri dört ise, sonuç dizisinde yalnızca üç öğe olur.For example, if one sequence has three elements and the other one has four, the result sequence will have only three elements.

Şunlara uygulanır

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

Belirtilen iki dizideki öğeleri içeren bir tanımlama grubu sırası üretir.Produces a sequence of tuples with elements from the two specified sequences.

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

Tür Parametreleri

TFirst

İlk giriş dizisinin öğelerinin türü.The type of the elements of the first input sequence.

TSecond

İkinci giriş dizisinin öğelerinin türü.The type of the elements of the second input sequence.

Parametreler

first
IEnumerable<TFirst>

Birleştirilecek ilk dizi.The first sequence to merge.

second
IEnumerable<TSecond>

Birleştirilecek ikinci sıra.The second sequence to merge.

Döndürülenler

IEnumerable<ValueTuple<TFirst,TSecond>>

Bu sırada birinci ve ikinci dizilerden alınan öğeleri içeren bir tanımlama grubu dizisi.A sequence of tuples with elements taken from the first and second sequences, in that order.

Şunlara uygulanır