Partilhar via


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

Comments

  • Anonymous
    February 27, 2009
    PingBack from http://www.anith.com/?p=14151

  • Anonymous
    March 02, 2009
    .NET C# 4.0 : Named Arguments - New Extension Method “Zip” Back To Basics: Generational Garbage Collection

  • Anonymous
    March 02, 2009
    .NETC#4.0:NamedArguments-NewExtensionMethod“Zip”BackToBasics:GenerationalGarb...