const string[] DropDownListItems ={ "财政公告", "厅长文稿" };
提示错误:
编译器错误信息: CS0134: “DropDownListItems”的类型为“string[]”。只能用 null 对引用类型(字符串除外)的常量进行初始化
请问怎么解决?DropDownListItems 要在case语句中使用。

解决方案 »

  1.   

    看这个:
    http://msdn.microsoft.com/zh-tw/vstudio/ms228606.aspx
      

  2.   

    只有这个是可行的:    class Program
        {
            readonly string[] a = { "a", "b" };        static void Main(string[] args)
            {            const int b = 1;
                
            }
        }
      

  3.   


    switch case 语句要求是常量值,满足不了。
    我是c++学多了,有点傻了。
      

  4.   

               private void Form1_Load(object sender, EventArgs e)
            {
                string caseSwitch = "1";
                int ii = Array.IndexOf(a, caseSwitch);
                if (ii > -1)
                {
                    MessageBox.Show("found");
                }
                else
                {
                    MessageBox.Show("not found");
                }
            }
            readonly string[] a = { "a", "b" };
    这样做吧,找到就等于是执行Case后面的分支
      

  5.   

    改成if else 语句了。麻烦点。
      

  6.   

    都洗洗睡吧,看来是没从C习惯该过来
    const string[] DropDownListItems = new string[]{ "财政公告", "厅长文稿" };
      

  7.   

    C#只支持:   
    const   string  str= "";   
    const   int[]  int=   null;  
    const一般是编译期间直接直接copy到引用的地方
    可使用枚举