Linq Zip Operator

Gopesh9
Posted by Gopesh9 under LINQ category on | Points: 40 | Views : 969
Zip is used to thread two lists together. The result of Zip is an Enumerable.Here is the simple code which shows how you can use the same.

string[] str = { "a", "b", "c", "d" };
int[] num = { 1, 2, 3, 4 };

var stringWithNumbers = str.Zip(num, (str, num) => code + "," + state);
foreach ( var item in stringWithNumbers )
{
Console.WriteLine(item);
}

Output
a,1
b,2
c,3
d,4

Comments or Responses

Login to post response