Skip to content
Justice Tech School

C# Foreach

foreach visits every item in an array or collection without an index. You cannot change the collection while looping.

Example
string[] names = { "Ada", "Tunde", "Zainab" };
foreach (string n in names) Console.WriteLine(n);
foreach (char ch in "Go") Console.Write(ch + "-");

Exercise

Visit every item.

 (var x in list)

Quiz Test

Which loop suits collections?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.