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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM