CSharp - Statement foreach loops


foreach statement iterates over each element in an enumerable object.

Both an array and a string are enumerable.

The following code enumerates over the characters in a string, from the first character through to the last:


using System;
class MainClass//from   www .j av  a2s. c o m
   public static void Main(string[] args)
      foreach (char c in "book2s.com")   // c is the iteration variable
          Console.WriteLine (c);


Related Topics