C# 4.0 : New Extension Method “Zip”

C# 4.0 : New Extension Method “Zip”

  • Comments 3

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!!!

Leave a Comment
  • Please add 7 and 2 and type the answer here:
  • Post
Page 1 of 1 (3 items)