What is the use of Enumerable.Zip extension method in Linq? Ask Question

What is the use of Enumerable.Zip extension method in Linq? Ask Question

What is the use of Enumerable.Zip extension method in Linq?

ベストアンサー1

The Zip operator merges the corresponding elements of two sequences using a specified selector function.

var letters= new string[] { "A", "B", "C", "D", "E" };
var numbers= new int[] { 1, 2, 3 };
var q = letters.Zip(numbers, (l, n) => l + n.ToString());
foreach (var s in q)
    Console.WriteLine(s);

Ouput

A1
B2
C3

おすすめ記事