当前位置: 代码迷 >> C# >> C#无法将类型“string”隐式转换为“string[]”,该怎么解决
  详细解决方案

C#无法将类型“string”隐式转换为“string[]”,该怎么解决

热度:69   发布时间:2016-05-05 04:43:06.0
C#无法将类型“string”隐式转换为“string[]”
我现在想将selectName的值放入数组p 中,出现以下错误:无法将类型“string”隐式转换为“string[]”,代码如下
for (int i = 0; i < listBox3.Items.Count; i++)
            {
                string selectName1;
                selectName1 = listBox3.Items[i].ToString();
                string selectName2;
                selectName2 = listBox4.Items[i].ToString();
                string selectName = selectName1 + selectName2;
                string[] p = selectName;             //无法将类型“string”隐式转换为“string[]”
            }
------解决思路----------------------
string[] p = new string[10];
p[0] = selectName;

------解决思路----------------------
string selectName = selectName1 + selectName2;
string[] p = selectName;             //无法将类型“string”隐式转换为“string[]”
>=>
List<String> listS=new List<String>();
listS.Add( selectName1 + selectName2);
String[] str=listS.ToArray();
这样好了。
------解决思路----------------------
string selectName1;

selectName1 是个string类型的,赋值给string[] 是不对的。
------解决思路----------------------
字符串怎么可能与字符串数组相等呢……
你怎么也要有个放的规则吧
  相关解决方案