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

Published by

sornram9254

Ayutthaya Technical College/Voc.Cert.🛠️ | KMUTNB/B.S.Tech.Ed.⚙️ | Information Security Engineer 👨🏻‍💻| Penetration Tester👨🏻‍💻 | COYG🔴 Milan🔴⚫️ | Taylor Swift👩‍🎤 | ติ่งซีรีส์ญี่ปุ่น 🇯🇵

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.