c# foreach syntax code example
Example 1: get out of foreach statement c#
foreach (string s in sList)
{
if (s.equals("ok"))
{
break; // get out of the loop
}
}
Example 2: The foreach Loop c#
string[] names = {"William.", "James", "Oliver", "Lucas"};
foreach (string i in names)
{
Console.WriteLine(i);
}
Example 3: c# list foreach
someList.ForEach(x => { if(x.RemoveMe) someList.Remove(x); });