C Sharp Syntax - Control Structures - Iteration Structures - Foreach Loop

Foreach Loop

The foreach statement is derived from the for statement and makes use of a certain pattern described in C#'s language specification in order to obtain and use an enumerator of elements to iterate over.

Each item in the given collection will be returned and reachable in the context of the code block. When the block has been executed the next item will be returned until there are no items remaining.

foreach (int i in intList) { ... }

Read more about this topic:  C Sharp Syntax, Control Structures, Iteration Structures