vb.net 字符串的一维数组的值无法转换为字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20137937/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
value of 1 dimensional array of string cannot be converted to String
提问by NIMISH DESHPANDE
I am trying to assign values of array to a string, following is the code:
我正在尝试将数组的值分配给一个字符串,以下是代码:
oDocument1.IdentifierCode = lstFundIdentifiers.ToArray()
where IdentifierCode is a string while lstFundIdentifiers is declared as
其中 IdentifierCode 是一个字符串,而 lstFundIdentifiers 被声明为
ByVal lstFundIdentifiers As List(Of String).
ByVal lstFundIdentifiers As List(Of String).
I am not sure as to what is going wrong.
我不确定出了什么问题。
回答by Yatrix
String <> String()
字符串 <> 字符串()
Trying to assign an array to a string is like trying to put 4 tires on a unicycle. An array (or list) is a collection of objects, in your case, strings.
尝试将数组分配给字符串就像尝试将 4 个轮胎放在独轮车上。数组(或列表)是对象的集合,在您的情况下是字符串。
You can do this: yourArray(1) = yourStringor yourString = yourArray(0), but you can't do this: yourString = yourArray.
你可以这样做:yourArray(1) = yourString或yourString = yourArray(0),但你不能这样做:yourString = yourArray。
EDIT in response to your comment:
编辑以回应您的评论:
"So previously it was something like this oDocument.FundServCodes = lstFundServCodes.ToArray()"
“所以以前它是这样的 oDocument.FundServCodes = lstFundServCodes.ToArray()”
FundServCodes is an array itself, which is why that would work. You can easily confirm this by going to the class and looking at the FundServCodes property.
FundServCodes 本身就是一个数组,这就是为什么它会起作用。您可以通过转到该类并查看 FundServCodes 属性来轻松确认这一点。
EDIT 2:
编辑2:
These are basic programming concepts. Maybe you should go read up on collections, data types, objects, etc. There are 1000's of programming books and tutorials for all skill levels out there. Look one up and go through it.
这些是基本的编程概念。也许您应该阅读集合、数据类型、对象等方面的知识。那里有 1000 种适合所有技能水平的编程书籍和教程。查一查并通过它。

