Search This Blog

Thursday, December 5, 2013

Foreach in C# example

C# > Statements > foreach, in

Foreach iterates through the collection . It can be exited by the goto, return, or throw.
Note: Cannot be used to add or remove items from the collection to avoid unpredictable side effects

Example


int[] intarray = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

foreach (int el in intarray)
{
MessageBox.Show(el.ToString()); 
}