请教关于数组赋值问题
我定义一个数组,想要根据条件不同而赋值也不同,如:string[] arrStr;
if(code=="10001")
{
     arrStr = {"sdf","sdf","dfghfgh","sadas"};
}
else if(code=="1002")
{
     arrStr = {"545","9878","996","88555"};
}这样应该如何实现?谢谢

解决方案 »

  1.   

    建议用ArrayList ArrayList ArrL=new ArrayList();
    if(code=="10001")
    {
    ArrL.Add("sdf");
    ArrL.Add("sdf");
    ArrL.Add("dfghfgh");
    ArrL.Add("sadas");
    }
    else if(code=="1002")
    {
    ArrL.Add("545");
    ArrL.Add("9878");
    ArrL.Add("996");
    ArrL.Add("88555");
    }
      

  2.   

    string[] arrStr;
    if(code=="10001")
    {
    arrStr =new string[] {"sdf","sdf","dfghfgh","sadas"};
    }
    else if(code=="1002")
    {
    arrStr = new string[]{"545","9878","996","88555"};
    }
      

  3.   

    错了,string[] arrStr必须赋值,所以有else{arrStr = new string[]{"","","",""};}
    string[] arrStr;
    if(code=="10001")
    {
    arrStr =new string[] {"sdf","sdf","dfghfgh","sadas"};
    }
    else if(code=="1002")
    {
    arrStr = new string[]{"545","9878","996","88555"};
    }
    else
    {
    arrStr = new string[]{"","","",""};
    }