首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#字符串数组常量?解决办法

2012-01-19 
C#字符串数组常量?C#中能否定义字符串数组常量,该怎么定义?eg:C# codepublic const str[]new string[3]{

C#字符串数组常量?
C#中能否定义字符串数组常量,该怎么定义?
eg:

C# code
public const str[]=new string[3]{"ab","bc","cd"};

上面的语句编译出错:

错误信息:类型为“string[]”。只能用 null 对引用类型(字符串除外)的常量进行初始化

[解决办法]
C# code
public static readonly string[] str = new string[3] { "ab", "bc", "cd" };
[解决办法]
探讨
C# code
public static readonly string[] str = new string[3] { "ab", "bc", "cd" };

[解决办法]
觉得不方便你就用List<string>算了,功能比定义string[] 数组强

热点排行