我正在尝试在C#中打印二维数组。我已经成功地正确打印了列和行,但是我不知道如何使它们正确对齐,所以它是一个正方形。有什么方法可以格式化它,使其看起来像一个合适的正方形? (如形状所示)
我的代码是
int[,] array1 = new int[6,6]
{
{10,20,10,21,99 },{2,27,5,45,13 },{17,33,20 },{21,35,15,54,37 },{31,101,25,55,26,66 },{45,44,12,98 }
};`
int Length = array1.GetLength(0);
int Height = array1.GetLength(1);
for (int i = 0; i < Length; i++)
{
for (int j = 0; j < Height; j++)
{
Console.Write(string.Format("{0} ",array1[i,j]));
}
Console.Write("\n" + "\n");
}