错误消息:无法将类型“字符串"转换为“字符串[]"
问题描述:
我正在创建一个动态数组,但出现错误:
I am creating a dynamic array, and getting an error:
错误消息:无法将类型字符串"转换为字符串[]"
代码是:
arrTeamMembers += tb.Text;
tb.Text 包含诸如Michael | Steve | Thomas | Jeff | Susan | Helen |"之类的值
tb.Text contains values such as "Michael | Steve | Thomas | Jeff | Susan | Helen |"
我正在尝试将值从 tb.Text 传递给 arrTeamMembers.我不是要拆分文本.我该如何解决这个错误?
I am trying to pass the values from tb.Text to arrTeamMembers. I am NOT trying to split the text. How can I resolve this error?
答
您不能只将字符串添加到字符串数组中.
You can't just add strings to an array of strings.
根据您实际尝试执行的操作,您可能需要:
Depending on what you are actually trying to do, you might want this:
string[] arrTeamMembers = new string[] { tb.Text };
或
arrTeamMembers[0] = tb.Text;
您可能想改用列表.
List<string> stringlist = new List<string>();
stringlist.Add(tb.Text);