Suppose I have 2 enumerations that I know have the same number of elements and each element “corresponds” with the identically placed element in the other enumeration. Is there a way to process these 2 enumerations simultaneously so that I have access to the corresponding elements of each enumeration at the same time?
Using a theoretical LINQ syntax, what I have in mind is something like:
from x in seq1, y in seq2
select new {x.foo, y.bar}
Since Neil Williams deleted his answer, I’ll go ahead and post a link to an implementation by Jon Skeet.
To paraphrase the relevant portion:
Note that the
KeyValuePair<>is my addition, and that I’m normally not a fan of using it this way. Instead, I would define a genericPairorTupletype. However, they are not included in the current version of the framework and I didn’t want to clutter this sample with extra class definitions.