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