new 了一个类数组, 结果赋值时提示空引用异常. 方法错误吗,怎么用才对?
非常感谢! class State
{
private int stateCode;
private string stateText; /// <summary>
/// 状态代码
/// </summary>
public int StateCode
{
set
{
this.stateCode = value;
}
get
{
return this.stateCode;
}
} /// <summary>
/// 状态文本
/// </summary>
public string StateText
{
set
{
this.stateText = value;
}
get
{
return this.stateText;
}
}
} State[] states = new State[4]; this.states[0].StateCode = 1;
this.states[0].StateText = "在线";
this.states[1].StateCode = 2;
this.states[1].StateText = "暂离";
this.states[2].StateCode = 3;
this.states[2].StateText = "忙碌";
this.states[3].StateCode = 4;
this.states[3].StateText = "离线";
非常感谢! class State
{
private int stateCode;
private string stateText; /// <summary>
/// 状态代码
/// </summary>
public int StateCode
{
set
{
this.stateCode = value;
}
get
{
return this.stateCode;
}
} /// <summary>
/// 状态文本
/// </summary>
public string StateText
{
set
{
this.stateText = value;
}
get
{
return this.stateText;
}
}
} State[] states = new State[4]; this.states[0].StateCode = 1;
this.states[0].StateText = "在线";
this.states[1].StateCode = 2;
this.states[1].StateText = "暂离";
this.states[2].StateCode = 3;
this.states[2].StateText = "忙碌";
this.states[3].StateCode = 4;
this.states[3].StateText = "离线";
states[0]=new State();
this.states[0].StateCode = 1;
this.states[0].StateText = "在线";states[1]=new State();
this.states[1].StateCode = 2;
this.states[1].StateText = "暂离";states[2]=new State();
this.states[2].StateCode = 3;
this.states[2].StateText = "忙碌";states[3]=new State();
this.states[3].StateCode = 4;
this.states[3].StateText = "离线";
this.states[0].StateCode = 1;