菜鸟求救 C# 二维数组初始化问题
class Cells
{
private int maxx;
private int maxy;
private int x;//数组坐标X
private int y;//数组坐标Y
private estate[,] state;//状态
public enum eshape { square, circle, custom };//(正方形,圆形,自定义)
}
public Cells() //构造函数
{
maxx = 1;
maxy = 1;
x = 1;
y = 1;
estate[,] state = new estate[maxx, maxy];
for (int i = 0; i < maxx; i++)
for (int j = 0; j < maxy; y++)
this.state[x, y] = estate.dead;(该行出错)
}
异常:
未处理NullReferenceException
未将对象引用设置到对象的实例。
疑难解答提示:
使用“new”关键字创建对象实例。
在调用方法前,通过检查对象是否为null。