Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下のような 2 つの foreach ループがある場合:
foreach(var a in b) foreach(var c in d) combining them into single foreach loop foreach(var e in both b and d)
いいえ、「両方」の構文はありません。あなたが何を求めているのかはまったく不明です。連結したい場合は、
foreach(var e in b.Concat(d))
組み合わせたセットが必要な場合:
foreach(var e in b.Union(d))
または両方に共通のセット:
foreach(var e in b.Intersect(d))
クロス結合が必要な場合は、おそらくSelectMany. しかし率直に言って、ネストされたforeachものはあなたの場合と同じくらい合理的で効果的です。
SelectMany
foreach