I have two enumerables: IEnumerable<A> list1 and IEnumerable<B> list2. I would like to iterate through them simultaneously like:
foreach((a, b) in (list1, list2))
{
// use a and b
}
If they don’t contain the same number of elements, an exception should be thrown.
What is the best way to do this?
Here’s an implementation of this operation, typically called Zip:
To make it throw an exception if just one of the sequences run out of values, change the while-loop so: