1
我敢肯定,我已經初始化的一切,但它仍然拋出錯誤在初始化數組變量
「對象引用不設置到對象的實例。」
Cell[,] cell;
bool[,] UpdateCell;
int AreaSizeX;
int AreaSizeY;
int MaxAge;
public void Reset(int areaSizeX, int areaSizeY, int maxAge)
{
AreaSizeX = areaSizeX;
AreaSizeY = areaSizeY;
MaxAge = maxAge;
cell = new Cell[AreaSizeX, AreaSizeY];
UpdateCell = new bool[AreaSizeX, AreaSizeY];
for (int i = 0; i < areaSizeX; i++)
{
for (int j = 0; j < areaSizeY; j++)
{
cell[i, j].Alive = false; //throws exception here #########
cell[i, j].Age = 0;
UpdateCell[i, j] = false;
}
}
}
這段代碼有什麼問題? C#不允許動態創建數組?
中當然,就像我可以輸入Skeet一樣。 ;) –
哦,看他回答得有多快! –