是什么区别const,并readonly和你使用一个比其他?
我正在尝试创建一个2D数组来存储一些不会像这样改变的值.
const int[,] hiveIndices = new int[,] {
{200,362},{250,370},{213,410} ,
{400,330} , {380,282} , {437, 295} ,
{325, 405} , {379,413} ,{343,453} ,
{450,382},{510,395},{468,430} ,
{585,330} , {645,340} , {603,375}
};
Run Code Online (Sandbox Code Playgroud)
但是在编译时我得到了这个错误
hiveIndices is of type 'int[*,*]'.
A const field of a reference type other than string can only be initialized with null.
Run Code Online (Sandbox Code Playgroud)
如果我改变const to static,它会编译.我不明白添加const量词应该如何引发这种行为.