S_Cell 是一个类S_Cell[,] cell = new S_Cell[9, 9];
然后 cell[0,0].x=1;
出错,显示:未将对象引用设置到对象的实例。然后设置断点,看到 cell的所有成员的数据都是 NULL这是什么情况?

解决方案 »

  1.   

    S_Cell[,] cell = new S_Cell[9, 9]; 
    cell[0,0] = new S_Cell();
    cell[0,0].x = 1; 
      

  2.   

        S_Cell[,] cell = new S_Cell[9, 9]; 
        for (int i = 0; i < cell.GetLength(0); i++)
          for (int j = 0; j < cell.GetLength(1); j++)
            cell[i, j] = new S_Cell();
        cell[0,0].x = 1; 
      

  3.   

    那要看是类对象,还是基本类型了,基本类型不需要实例化,但是类对象的话是需要的。像string是不需要的,String严格上是需要的,只是重写了也就不需要了。