[英]use of array of structs in c#
我需要有關結構初始化的數組的幫助。 在下面的代碼中,我們如何完成注釋中定義的初始化?
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 ??
}
}
}
謝謝..
C#中成員的默認可訪問性是私有的,這就是賦值語句失敗的原因。 您需要通過向其添加internal
或public
來使字段可訪問。
struct state{
internal int previousState;
internal int currentState;
}
durum =新州[5]; - >僅為5個元素創建數組。
您需要初始化數組中的每個元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.