CSharp examples for Language Basics:for each
The format of the foreach command is shown here:
foreach( datatype varname in arrayName ) { statements; }
Using foreach with an Array
using System;//from ww w .j ava2 s .c o m public class MainClass { public static void Main() { char[] name = new char[] {'B','r','a','d','l','e','y'}; Console.WriteLine("Display content of name array..."); foreach( char x in name ) { Console.Write("{0}", x); } Console.WriteLine("\n...Done."); } }