错误消息:无法将类型“字符串"转换为“字符串[]" [英] Error message: Cannot convert type 'string' to 'string[]'
本文介绍了错误消息:无法将类型“字符串"转换为“字符串[]"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个动态数组,但出现错误:
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);
这篇关于错误消息:无法将类型“字符串"转换为“字符串[]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文