gpt4 book ai didi

c# - 初始化静态数组的正确语法

转载 作者:太空狗 更新时间:2023-10-30 00:14:23 26 4
gpt4 key购买 nike

<分区>

我有以下定义数组的代码

 public class PalphabetsDic
{
public static string[] PAlphCodes = new string[3] {
PAlphCodes[0] = "1593",
PAlphCodes[1] = "1604",
PAlphCodes[2] = "1740",
};
}

当我使用这个数组时

var text = PalphabetsDic.PAlphCodes[1]

给出错误:

The type initializer for 'Dota2RTL.PalphabetsDic' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.

有人可以帮我解决这个问题吗?

请注意 What is a NullReferenceException, and how do I fix it?涵盖数组,但 PAlphCodes = new string[3] 应该将其设置为非 null

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com