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