c# foreach循环二维数组

假设已有二维数组 array 行4, 列4
for(int i=0;i<4;i++)//行的行数
{
for(int j=0;j<4;j++)//行的列数
{
  console.wrie( array[i,j]+"\t" );
}
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

posted on 2017-01-01 02:34  防空洞123  阅读(7748)  评论(1编辑  收藏  举报

导航