本文介绍了动态填充字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何动态填充字符串数组?

我希望有一些显而易见的东西我在这里失踪


Option Strict On

dim s()as string

dim sTmp as string =" test"

dim i as integer


s(i)= new string(test)

上面的行给出 - 错误隐式转换字符串为1-dim数组

char

看了一下stringbuilder并转换为contructor中的char数组,但

没有找到答案

解决方案




我得到一个不同的错误:变量''test''没有声明。


你想把哪些值放在数组中?

-

Armin


如何报价以及原因:







我感到很遗憾,但我无法理解你想要什么。




-

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>




这与你引用数组的事实有关/>
索引[ie-s(i)]并且还通过

隐式标注数组的大小,指定索引的值[即 - (测试)这是错误的,

by-by-by]


试试这个:


选项严格打开

Dim s()As String

Dim sTmp As String =" test"

Dim i As Integer


s(i)=" test"

- 或 -

s(i)= sTmp


-----

作为旁注,如果你想创建一个数组,而不是直接将它标注为

,你可以说:

Dim s()As String = {" One"," Two"" Three" }


希望这有帮助


J.

-

电子邮件列出的地址不是我的真实地址。请不要发送

有效电子邮件到该地址。


How do I dynamically populate a string array?
I hope there is something obvious that I''m missing here

Option Strict On
dim s() as string
dim sTmp as string = "test"
dim i as integer

s(i)=new string(test)
Above line gives - error implicit conversion string to 1-dim array of
char
Looked at stringbuilder and coverting to char array in contructor but
did not find an answer

解决方案



I get a different error: variable ''test'' not declared.

Which values do you want to put in the array?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html




I feel sorry, but I am not able to understand what exactly you want to
do.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>




It has something to do with the fact that you''re referencing the array
index [i.e.- s(i)] and also implicitly dimensioning your array by
specifying values for the indices [i.e. - (test) which is erroneous,
by-the-by]

Try this:

Option Strict On
Dim s() As String
Dim sTmp As String = "test"
Dim i As Integer

s(i) = "test"
--or--
s(i) = sTmp

-----
As a side note, if you wanted to create an array, and not dimension it
directly, you could say:
Dim s() As String = { "One", "Two", "Three" }

Hope this helped

J.
--
The email address listed is not my real address. Please do not send
valid email to that address.


这篇关于动态填充字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 23:25
查看更多