Enumerable.Zip メソッド

定義

オーバーロード

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

2 つのシーケンスの対応する要素に対して、1 つの指定した関数を適用し、結果として 1 つのシーケンスを生成します。

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

指定された 3 つのシーケンスの要素を含むタプルのシーケンスを生成します。

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

指定された 2 つのシーケンスの要素を持つタプルのシーケンスを生成します。

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

Source:
Zip.cs
Source:
Zip.cs
Source:
Zip.cs

2 つのシーケンスの対応する要素に対して、1 つの指定した関数を適用し、結果として 1 つのシーケンスを生成します。

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

1 番目の入力シーケンスの要素の型。

TSecond

2 番目の入力シーケンスの要素の型。

TResult

結果のシーケンスの要素の型。

パラメーター

first
IEnumerable<TFirst>

マージする 1 番目のシーケンス。

second
IEnumerable<TSecond>

マージする 2 番目のシーケンス。

resultSelector
Func<TFirst,TSecond,TResult>

2 つのシーケンスの要素をマージする方法を指定する関数。

戻り値

IEnumerable<TResult>

2 つの入力シーケンスのマージされた要素が格納されている IEnumerable<T>

例外

first または secondnull です。

次のコード例では、 メソッドを使用 Zip して 2 つのシーケンスをマージする方法を示します。

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して列挙されるまで実行されません。

メソッドは、最初のシーケンスの各要素を、2 番目のシーケンスで同じインデックスを持つ要素とマージします。 シーケンスに同じ数の要素がない場合、メソッドはいずれかの要素の末尾に達するまでシーケンスをマージします。 たとえば、1 つのシーケンスに 3 つの要素があり、もう 1 つのシーケンスに 4 つの要素がある場合、結果シーケンスには 3 つの要素のみが含まれます。

こちらもご覧ください

適用対象

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

Source:
Zip.cs
Source:
Zip.cs
Source:
Zip.cs

指定された 3 つのシーケンスの要素を含むタプルのシーケンスを生成します。

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

1 番目の入力シーケンスの要素の型。

TSecond

2 番目の入力シーケンスの要素の型。

TThird

3 番目の入力シーケンスの要素の型。

パラメーター

first
IEnumerable<TFirst>

マージする 1 番目のシーケンス。

second
IEnumerable<TSecond>

マージする 2 番目のシーケンス。

third
IEnumerable<TThird>

マージする 3 番目のシーケンス。

戻り値

IEnumerable<ValueTuple<TFirst,TSecond,TThird>>

1 番目、2 番目、および 3 番目のシーケンスから取得された要素を持つタプルのシーケンス 。その順序。

こちらもご覧ください

適用対象

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

Source:
Zip.cs
Source:
Zip.cs
Source:
Zip.cs

指定された 2 つのシーケンスの要素を持つタプルのシーケンスを生成します。

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

1 番目の入力シーケンスの要素の型。

TSecond

2 番目の入力シーケンスの要素の型。

パラメーター

first
IEnumerable<TFirst>

マージする 1 番目のシーケンス。

second
IEnumerable<TSecond>

マージする 2 番目のシーケンス。

戻り値

IEnumerable<ValueTuple<TFirst,TSecond>>

最初のシーケンスと 2 番目のシーケンスから取得された要素が、その順序で備えられているタプルのシーケンス。

こちらもご覧ください

適用対象