我需要有关结构初始化的数组的帮助.在下面的代码中,我们如何完成注释中定义的初始化?
class structExample
{
struct state{
int previousState;
int currentState;
}
static state[] durum;
public static void main(String[] args)
{
durum = new state[5];
// how we can assign new value to durum[0].previousState = 0; doesn't work ??
}
}
Run Code Online (Sandbox Code Playgroud)
}
谢谢..
C#中成员的默认可访问性是私有的,这就是赋值语句失败的原因.您需要通过添加internal或删除字段来使字段可访问public.
struct state{
internal int previousState;
internal int currentState;
}
Run Code Online (Sandbox Code Playgroud)