A const field of a reference type other than string can only be initialized with null Error
本问题已经有最佳答案,请猛点这里访问。
我试图创建一个二维数组来存储一些不会像这样改变的值。
1 2 3 4 5 6 7 | 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} }; |
但是在编译时,我得到了这个错误
1 2 | hiveIndices is of type 'int[*,*]'. A const field of a reference type other than string can only be initialized with null. |
如果我更改
实际上,您正试图使数组(它是一个引用类型)
你可能在找
有关更多信息,请参阅相应的编译器错误CS0134:
A constant-expression is an expression that can be fully evaluated at
compile-time. Because the only way to create a non-null value of a
reference-type is to apply the new operator, and because the new
operator is not permitted in a constant-expression, the only possible
value for constants of reference-types other than string is null.