我是 C# 的初学者,我不断收到“System.NullReferenceException”错误。我到处寻找,但似乎找不到有用的解决方案。我简化了下面的代码,以便更清楚。
namespace tile_test
{
public class Game1 : Game
{
public static float bottomWorld = 38400f;
public static float rightWorld = 134400f;
public static int maxTilesX = (int)rightWorld / 16 + 1;
public static int maxTilesY = (int)bottomWorld / 16 + 1;
public Game1()
{
Tile[,] tile = new Tile[maxTilesX, maxTilesY];
int x = 1;
int y = 1;
tile[x, y].active = false; //Error on this line.
}
}
}
Tile 类如下所示
namespace tile_test
{
public class Tile
{
public bool active;
}
}
谁能帮帮我?