列表(字符串) [英] list (of string)
问题描述
大家好,很抱歉这个愚蠢的问题,但我不明白.......
Hi all, sorry for this silly question but i don't understand.......
在我的代码中,我有一个字符串数组".
In my code i have an "array of string".
昏暗地址(20000)作为字符串
Dim addresses(20000) As String
我想改用List(of String).
I wanted to use the List(of String) instead.
所以我尝试了:
昏暗的地址作为新列表(字符串)
Dim Addresses as new list(of String)
在执行过程中,它给了我错误,我认为这是因为我没有初始化列表.
During exection, it gives me error and i have thought it was because i didn't initialize the list.
我的问题是....
My question is ....
我可以如下初始化它:
从{",,",}}开始的昏暗地址为List(Of String)= New List(Of String)
Dim addresses As List(Of String) = New List(Of String) From {"", "",""}
但是从一开始我就必须知道列表中有多少个项目.
But from the beginning i must know how many items are in the list.
我知道我必须在初始化之前将其初始化,但是如果我不知道其中有多少个字符串,我怎么能使用列表(字符串)?会在那里吗?
I know that i must initialize it BEFORE, but how the hell can i use the list(of String), if i DON'T KNOW how many strings are in there ? Will be there ??
在这种情况下,数组比较容易.我将其调暗为最多20000个对象.
The array in this case is easier. I dim it as a max of 20000 object.
并带有列表(字符串)?????????????
And with the list(of string) ?????????????
非常感谢.
推荐答案
莱昂纳多
您不需要事先知道多少?它将动态分配所需的内容:
You don't need to know how many in advance; it will dynamically allocate what's needed:
Dim Addresses As New List(Of String)
' At some point later:
Addresses.Add("this is a string")
这篇关于列表(字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!