Using LINQ's Zip query operator

The Zip query operator was not included in LINQ initially but was added as an afterthought in .NET 4.0.

It operates on two sequences in parallel, returning another sequence whose elements are the result of applying a method to corresponding pairs of elements from the input sequences.

The name appears to have been chosen because it works a bit like a zipper.

A simple example should help to make it clear how it works.

Suppose you have two arrays of equal length. The first array contains some numbers, the second array contains some names corresponding to those numbers and you'd like to produce an array of strings combining this information.

If the input sequences are of unequal length, then the output sequence will have the length of the smaller sequence and the additional elements of the other sequence will be ignored. So, if we change the integer array in the above code to: