二维方形单元阵列构造错误

时间:2014-10-22 19:56:34

标签: c# arrays multidimensional-array cell

我开始使用2D寻路引擎,但是它给了我2D数组构造函数中的下一个错误 在Field类中,它的实际数组有一个变量c

public void FieldBuild(
    int LowerLeftX, 
    int LowerLeftY, 
    int UpperRightX, 
    int UpperRightY, 
    bool Walkable)
{
    int CellsConstructed = 0;
    for (int Xctr = LowerLeftX; Xctr <= UpperRightX; Xctr++)
    {
        for (int Yctr = LowerLeftY; Yctr <= UpperRightY; Yctr++)
        {
            this.c[Xctr,Yctr] = new Cell(Xctr, Yctr); //error on this line
            this.c[Xctr,Yctr].IsWalkable = Walkable;
            CellsConstructed++;
        }
    }
    Console.WriteLine("Constructed {0} cells.", CellsConstructed);
}

告诉我它出现NullReferenceException错误

0 个答案:

没有答案