作者:高傲的辫子 | 来源:互联网 | 2023-05-25 13:57
我有以下代码定义一个数组
public class PalphabetsDic
{
public static string[] PAlphCodes = new string[3] {
PAlphCodes[0] = "1593",
PAlphCodes[1] = "1604",
PAlphCodes[2] = "1740",
};
}
当我使用这个数组
var text = PalphabetsDic.PAlphCodes[1]
给出错误:
'Dota2RTL.PalphabetsDic'的类型初始值设定项引发了异常.---> System.NullReferenceException:对象引用未设置为对象的实例.
请有人帮我这个吗?
请注意什么是NullReferenceException,我该如何解决?涵盖数组,但PAlphCodes = new string[3]
应该将其设置为不null
.
1> 小智..:
初始化您的方式时,您不需要索引值:
public static string[] PAlphCodes = new string[] {
"1593",
"1604",
"1740",
};