int[,] a = {{1,2},{3,4}};
int[,] b = new int[2,2];
b[0,0] = 1;
b[0,1] = 2;
b[1,0] = 3;
b[1,1] = 4;
for (int i=0; i<=a.GetUpperBound(0); i++)
{
for (int j=0; j<=a.GetUpperBound(1); j++)
{
Console.WriteLine("a[{0},{1}]={2}",i,j, a[i,j]);
}
}
for (int i=0; i<=b.GetUpperBound(0); i++)
{
for (int j=0; j<=b.GetUpperBound(1); j++)
{
Console.WriteLine("b[{0},{1}]={2}",i,j, b[i,j]);
}
}
以上实例中二维数组a,b存储的数据一样。
注意C#的数组声明和初始化, 与C/C++的区别。