Accepted answer is correct and perfectly fine. I just wanted to mention another, perhaps more convenient way how to traverse Multidemensional arrays, by making use of IEnumerable interface.
This approach is in my opinion more convenient than iterating using indeces, but there is slight overhead of creating the iterator and each step calling MoveNext() on the iterator, so it is a little bit slower.
Example of using IEnumerable from c# docs:
int[,] numbers2D = { { 9, 99 }, { 3, 33 }, { 5, 55 } };
foreach (int i in numbers2D)
{
System.Console.Write($"{i} ");
}
// Output: 9 99 3 33 5 55
int[,,] array3D = new int[,,] { { { 1, 2, 3 }, { 4, 5, 6 } },
{ { 7, 8, 9 }, { 10, 11, 12 } } };
foreach (int i in array3D)
{
System.Console.Write($"{i} ");
}
// Output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
Note that jagged arrays surprisingly cannot be traversed using IEnumerable interface.