Monday, September 15, 2014

Zip extension method introduced in C# 4.0


This is a combining operator which combines items from one collection with item from second that are in the same position in the collection. See the example.

 class Program
  {
    static void Main()
    {
      var firstCollection = new List<string> { "Nalani ""Kamal ""Waruna ""Amal ""Surani " };
      var secondCollection = new List<string> { "Jayasundara""Amarasinghe""Hewage""Jayasinghe""Hasanthika" };
 
      firstCollection
        .Zip(secondCollection, (a, b) => a + b)
        .ToList()
        .ForEach(i => Console.WriteLine(i));
 
      Console.ReadLine();
    }
  }


No comments:

Post a Comment