How to iterate through two IEnumerables simultaneously?

You want something like the Zip LINQ operator – but the version in .NET 4 always just truncates when either sequence finishes.

The MoreLINQ implementation has an EquiZip method which will throw an InvalidOperationException instead.

var zipped = list1.EquiZip(list2, (a, b) => new { a, b });

foreach (var element in zipped)
{
    // use element.a and element.b
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)