c# foreach循环二维数组

假设已有二维数组 array 行4, 列4
for(int i=0;i<4;i++)//行的行数
{
for(int j=0;j<4;j++)//行的列数
{
  console.wrie( array[i,j]+" " );
}
console.writeline();
}

不用嵌套foreach
看代码:
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
原文地址:https://www.cnblogs.com/as3lib/p/6240658.html