【发布时间】:2019-09-15 12:05:45
【问题描述】:
我正在尝试打印一个具有空值的 Int 二维数组。这基本上就像在字符串数组中分配一个空间。
int[,] arr = new int[10, 10];
for (int temp = 0; temp < arr.GetLength(0); temp++)
{
for (int temp2 = 0; temp2 < arr.GetLength(1); temp2++)
{
arr[temp, temp2] = xxxxx ;
}
}
for (int xIndex = 0; xIndex < arr.GetLength(0); xIndex++)
{
for (int yLoop = 0; yLoop < arr.GetLength(1); yLoop++)
{
Console.Write(arr[xIndex, yLoop]);
}
Console.WriteLine();
}
到目前为止,我尝试分配 null 值,但我得到“无法将 null 转换为 'int',因为它是不可为 null 的值类型。 如果我不分配任何值,它只是简单地输出 0 并且我希望它在控制台中不显示任何内容。
【问题讨论】: