Enumerable.Zip メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
オーバーロード
| 名前 | 説明 |
|---|---|
| Zip<TFirst,TSecond,TResult>(IEnumerable<TFirst>, IEnumerable<TSecond>, Func<TFirst,TSecond,TResult>) |
指定した関数を 2 つのシーケンスの対応する要素に適用し、結果のシーケンスを生成します。 |
| 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>)
- ソース:
- Zip.cs
- ソース:
- Zip.cs
- ソース:
- Zip.cs
- ソース:
- Zip.cs
- ソース:
- Zip.cs
指定した関数を 2 つのシーケンスの対応する要素に適用し、結果のシーケンスを生成します。
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
2 番目の入力シーケンスの要素の型。
- TResult
結果シーケンスの要素の型。
パラメーター
- first
- IEnumerable<TFirst>
マージする最初のシーケンス。
- second
- IEnumerable<TSecond>
マージする 2 番目のシーケンス。
- resultSelector
- Func<TFirst,TSecond,TResult>
2 つのシーケンスの要素をマージする方法を指定する関数。
返品
2 つの入力シーケンスのマージされた要素を含む IEnumerable<T> 。
例外
first または second が null。
例
次のコード例では、 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# で foreach を使用するか、Visual Basic で For Each を使用して列挙されるまで実行されません。
このメソッドは、最初のシーケンスの各要素を、2 番目のシーケンスで同じインデックスを持つ要素とマージします。 シーケンスが同じ数の要素を持たない場合、メソッドはいずれかの要素の末尾に達するまでシーケンスをマージします。 たとえば、1 つのシーケンスに 3 つの要素があり、もう 1 つのシーケンスに 4 つの要素がある場合、結果シーケンスには 3 つの要素のみが含まれます。
こちらもご覧ください
適用対象
Zip<TFirst,TSecond,TThird>(IEnumerable<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>)
- ソース:
- Zip.cs
- ソース:
- Zip.cs
- ソース:
- Zip.cs
- ソース:
- Zip.cs
- ソース:
- 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
最初の入力シーケンスの要素の型。
- TSecond
2 番目の入力シーケンスの要素の型。
- TThird
3 番目の入力シーケンスの要素の型。
パラメーター
- first
- IEnumerable<TFirst>
マージする最初のシーケンス。
- second
- IEnumerable<TSecond>
マージする 2 番目のシーケンス。
- third
- IEnumerable<TThird>
マージする 3 番目のシーケンス。
返品
最初のシーケンス、2 番目、および 3 番目のシーケンスから取得された要素を含むタプルのシーケンス。その順序で指定します。
こちらもご覧ください
適用対象
Zip<TFirst,TSecond>(IEnumerable<TFirst>, IEnumerable<TSecond>)
- ソース:
- Zip.cs
- ソース:
- Zip.cs
- ソース:
- Zip.cs
- ソース:
- Zip.cs
- ソース:
- 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
最初の入力シーケンスの要素の型。
- TSecond
2 番目の入力シーケンスの要素の型。
パラメーター
- first
- IEnumerable<TFirst>
マージする最初のシーケンス。
- second
- IEnumerable<TSecond>
マージする 2 番目のシーケンス。
返品
最初のシーケンスと 2 番目のシーケンスから取得された要素を含むタプルのシーケンス。その順序です。