LINQ has a new extension method in the .NET Framework 4, called Zip, that exists on both IEnumerable<T> and IQueryable<T>. Zip is a neat Extension Method that allows one to merge two sequences into a single sequence using a predicate function.
IEnumerabe<T>.Zip
Let’s use the new LINQ Zip Extension Method in LINQ To Objects to merge two sequences using a predicate function. The first sequence will contain the names of the months of the year. The second sequence will contain the number of days in each month for 2009. We will combine those two sequences into a sentence that says “January has 31 days”, where January and 31 will be replaced by the appropriate month name and number of days in the sequences.
Here is the sample C# code that creates the two sequences, merges them using the new LINQ Zip Extension Method, and displays them on the console:
// Get Names of Months
var months = from i in Enumerable.Range(1, 12)
select new DateTime(2009,i,1).ToString("MMMM");
// Get Number of Days in Each Month
var daysInMonths = from i in Enumerable.Range(1, 12)
select DateTime.DaysInMonth(2009,i).ToString();
// Combine
var combined = months.Zip(daysInMonths, (month, day)
=> string.Format("{0} has {1} days", month,day));
// Display
combined.ToList().ForEach(d => Console.WriteLine(d));
Console.ReadLine();
You could achieve the same thing using existing LINQ Extension Methods, but having such an extension method clearly shows your intentions and thus allows for better performance and other optimizations that can be achieved in the underlying framework.
The results is as follows:

Hope this helps!

Zip is nothing new. Python has had it since 2.0 circa 2000
Posted by: Edward J. Stembler | 12/14/2009 at 08:52 AM
I swear, the .Net framework team must be looking hard at dynamic languages:
http://ruby-doc.org/core/classes/Enumerable.html#M003138
http://docs.python.org/library/functions.html
# Insert gratuitous jab at C# here
Posted by: Will Green | 12/14/2009 at 09:02 AM
Beautiful!
Posted by: spike | 12/14/2009 at 07:10 PM