C# 4.0 : New Extension Method “Zip”

While browsing the features I found an interesting extension method called “Zip”.

How it works, let’s check it.

List<string> names = new List<string>

{"Debajyoti", "Sumitra", "Wriju" , "Writam", "Tupur" };

List<int> ages = new List<int>{ 67, 58, 30, 24, 26 };

var zipped = names.Zip(ages, (name, age) => name + " is " + age + " years old.");

foreach (var item in zipped)

{

   Console.WriteLine(item);

}

Will give you the below output,

Debajyoti is 67 years old.

Sumitra is 58 years old.

Wriju is 30 years old.

Writam is 24 years old.

Tupur is 26 years old.

I love B#.

Namoskar!!!