数据类型[,] 数组名 = new 数据类型[行数,列数];
数据类型[,] 数组名 = new 数据类型[,]{
{0,0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,1,1,1,1}
}; //每一行对应一个大括号.
数组名.GetLength(轴向下标); //可以获得某个轴向的元素个数.
int[,] intArray = new int[,]{
{1,2,3},
{11,22,33},
{111,222,333},
{1111,2222,3333}
};
for (int i = 0; i < intArray.GetLength(0); i++)
{
for (int j = 0; j < intArray.GetLength(1); j++)
{
Console.Write(intArray[i, j] + "\t");
}
Console.WriteLine();
}
Console.ReadKey();
int[,] gamesMap = new int[,]{
{1,1,0,1,1,1,1,0,1,1,1,1,1,1,1},
{1,0,0,0,0,0,1,0,0,0,0,0,1,1,1},
{1,1,0,0,0,0,0,0,1,0,0,0,0,1,1},
{1,1,0,0,0,0,1,0,0,0,0,0,0,1,1},
{1,1,1,0,0,1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,1,0,0,1,0,1,1,1,1,1},
{1,0,0,0,0,0,1,0,0,0,0,0,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,0,1,1,1}
};
for (int i = 0; i < gamesMap.GetLength(0); i++)
{
for(int j = 0; j < gamesMap.GetLength(1); j++)
{
if(gamesMap[i,j] == 1)
{
Console.Write("■");
}
if(gamesMap[i, j] == 0)
{
Console.Write("□");
}
}
Console.WriteLine();
}
Console.ReadKey();