C#字符串数组常量?解决办法
C#字符串数组常量?C#中能否定义字符串数组常量,该怎么定义?eg:C# codepublic const str[]new string[3]{
C#字符串数组常量?
C#中能否定义字符串数组常量,该怎么定义?
eg:
C# codepublic const str[]=new string[3]{"ab","bc","cd"};
上面的语句编译出错:
错误信息:类型为“string[]”。只能用 null 对引用类型(字符串除外)的常量进行初始化
[解决办法]C# codepublic static readonly string[] str = new string[3] { "ab", "bc", "cd" };
[解决办法]
[解决办法]
觉得不方便你就用List<string>算了,功能比定义string[] 数组强