CSharp examples for Language Basics:for each
The foreach statement iterates over each element in an enumerable object.
For example, both an array and a string are enumerable.
Here is an example of enumerating over the characters in a string, from the first character through to the last:
using System;/*from w ww . j ava 2 s. c o m*/ class Test { static void Main(){ foreach (char c in "asdf") // c is the iteration variable Console.WriteLine (c); } }