在c#中使用结构数组

dnu*_*nur 3 c# struct

我需要有关结构初始化的数组的帮助.在下面的代码中,我们如何完成注释中定义的初始化?

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)

}

谢谢..

Jar*_*Par 6

C#中成员的默认可访问性是私有的,这就是赋值语句失败的原因.您需要通过添加internal或删除字段来使字段可访问public.

struct state{
    internal int previousState;
    internal int currentState;
}
Run Code Online (Sandbox Code Playgroud)