How do I 'foreach' through a two-dimensional array?

Solution 1:

Multidimensional arrays aren't enumerable. Just iterate the good old-fashioned way:

for (int i = 0; i < table.GetLength(0); i++)
{
    Console.WriteLine(table[i, 0] + " " + table[i, 1]);
}

Solution 2:

As others have suggested, you could use nested for-loops or redeclare your multidimensional array as a jagged one.

However, I think it's worth pointing out that multidimensional arrays are enumerable, just not in the way that you want. For example:

string[,] table = {
                      { "aa", "aaa" },
                      { "bb", "bbb" }
                  };

foreach (string s in table)
{
    Console.WriteLine(s);
}

/* Output is:
  aa
  aaa
  bb
  bbb
*/