c# object array ForEach code example

Example 1: C# loop through array of objet

List<string> names = new List<string>() { "Suresh Dasari", "Rohini Alavala", "Trishika Dasari" };

            foreach (string name in names)

            {

                Console.WriteLine(name);

            }

Example 2: c# foreach arra

int[,] numbers2D = new int[3, 2] { { 9, 99 }, { 3, 33 }, { 5, 55 } };
// Or use the short form:
// int[,] numbers2D = { { 9, 99 }, { 3, 33 }, { 5, 55 } };

foreach (int i in numbers2D)
{
    System.Console.Write("{0} ", i);
}
// Output: 9 99 3 33 5 55