Answer:Iterate two Lists or Arrays with one ForEach statement in C#

var numbers = new [] { 1, 2, 3, 4 };
var words = new [] { “one”, “two”, “three”, “four” };

var numbersAndWords = numbers.Zip(words, (n, w) => new { Number = n, Word = w });
foreach(var nw in numbersAndWords)
{
Console.WriteLine(nw.Number + nw.Word);
}

ref: http://stackoverflow.com/a/1955780?stw=2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.