foreach in c#


                   The foreach loop is used with arrays and collections. The foreach loop accesses arrays  and collections in a unique way without using counters.

c# for loop uses counter while foreach can be used without counters.

For Each in C# Example

The program prints array elements using foreach loop.

using System;

namespace ProgramCall
{
    class foreachex
    {
        public static void Main()
        {


            int[] intarray = { 1, 2, 3, 4, 5, 6 };

            foreach (int i in intarray)
            {
                Console.WriteLine(i);
            }

            Console.ReadLine();
        }
    }
}

OUTPUT

1
2
3
4
5
6




foreach in c# foreach loop c# foreach loop c#.net foreach for each in c#