How do you loop through a multidimensional array?

后端 未结 7 1361
陌清茗
陌清茗 2021-01-03 19:50
foreach (String s in arrayOfMessages)
{
    System.Console.WriteLine(s);
}

string[,] arrayOfMessages is being passed in as a parameter

7条回答
  •  说谎
    说谎 (楼主)
    2021-01-03 20:29

    Don't use foreach - use nested for loops, one for each dimension of the array.

    You can get the number of elements in each dimension with the GetLength method.

    See Multidimensional Arrays (C# Programming Guide) on MSDN.

提交回复
热议问题