首页 > 编程语言 > 详细

c# foreach循环二维数组

时间:2017-01-01 07:47:28      阅读:219      评论:0      收藏:0      [点我收藏+]
假设已有二维数组 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

c# foreach循环二维数组

原文:http://www.cnblogs.com/as3lib/p/6240658.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!