Suppose you have an array of numbers, say, [1, 3, 5, 7, 9, …], and you want to pair each element up with its neighbour in the array, e.g. [[1, 3], [3, 5], [5, 7], [7, 9], …].
Sure, you can iterate through the indices of the elements and recursively grab the element at an index and its neighbour:
OR, you can use LINQ and the Zip method added in .Net 4 and do this instead:
A much more elegant solution, no? ;-)
Subscribe to my newsletter and get new contents delivered straight to your inbox :-)