[英]use of array of structs in c#
I need help about array of structs initiliazation. 我需要有关结构初始化的数组的帮助。 In a code something like below, how we can accomplish the initiliazation defined in comment ?? 在下面的代码中,我们如何完成注释中定义的初始化?
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 ??
}
}
} }
Thanks.. 谢谢..
The default accessibility for members in C# is private which is why the assignment statement is failing. C#中成员的默认可访问性是私有的,这就是赋值语句失败的原因。 You need to make the fields accessible by having adding internal
or public
to them. 您需要通过向其添加internal
或public
来使字段可访问。
struct state{
internal int previousState;
internal int currentState;
}
durum = new state[5]; durum =新州[5]; -> creates only the array for 5 elements. - >仅为5个元素创建数组。
You need to initialize every element inside the array. 您需要初始化数组中的每个元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.