【发布时间】:2022-11-22 13:14:59
【问题描述】:
大家好,如果之前有人问过这个问题,我深表歉意,但我找不到任何答案。我正在尝试制作一个二维数组,该数组分别在上方和左侧显示带有水平和垂直标签的数字。所以像这样:
The image attached here is the output I'm currently getting.
我创建了两个不同的一维数组来配合我的二维数字网格,以充当标签。但是,尽管我尝试更改这些数组出现的顺序、添加空格并更改其中的代码,但我无法以任何全面的方式对其进行格式化。我尝试了各种不同的格式化方式,但我就是想不通。这是我目前拥有的混乱代码:
public int[,] GetWeeklyAttendance()
{
string[] timeLabels =
{"1 PM ", "3 PM ", "5 PM ", "7 PM"};
string[] dayOfWeekLabels =
{"Monday\n", "Tuesday\n", "Wednesday\n", "Thursday\n", "Friday\n", "Saturday\n"};
int[,] weeklyAttendance =
{
{8, 10, 15, 20 },
{11, 15, 17, 18 },
{14, 12, 22, 20 },
{9, 14, 17, 12 },
{10, 12, 21, 22 },
{12, 12, 7, 15 }
};
for (int j = 0; j < dayOfWeekLabels.GetLength(0); j++)
{ Console.Write(dayOfWeekLabels[j]); }
for (int i = 0; i < timeLabels.GetLength(0); i++)
{ Console.Write(timeLabels[i]); }
for (int i = 0; i < weeklyAttendance.GetLength(0); i++)
{
for (int j = 0; j < weeklyAttendance.GetLength(1); j++)
{
Console.Write(weeklyAttendance[i, j] + " ");
}
Console.WriteLine();
}
return weeklyAttendance;
}
【问题讨论】: