How to iterate through two IEnumerables simultaneously?

Posted by Danvil on Stack Overflow See other posts from Stack Overflow or by Danvil
Published on 2010-04-27T14:17:50Z Indexed on 2010/04/27 14:23 UTC
Read the original article Hit count: 150

Filed under:

I have to enumerables IEnumerable<A> list1 and IEnumerable<B> list2 and would like to iterate through them simultaneously like:

foreach((a, b) in (list1, list2)) {
  // use a and b
}

If they do not contain the same number of elements, an exception should be thrown.

What is the best way to do this?

© Stack Overflow or respective owner

Related posts about c#