List(of String) or Array or ArrayList

后端 未结 7 2031
借酒劲吻你
借酒劲吻你 2021-01-01 10:27

Hopefully a simple question to most programmers with some experience.

What is the datatype that lets me do this?

Dim lstOfStrings as *IDK*

Dim Stri         


        
相关标签:
7条回答
  • 2021-01-01 11:18

    List(Of String) will handle that, mostly - though you need to either use AddRange to add a collection of items, or Add to add one at a time:

    lstOfString.Add(String1)
    lstOfString.Add(String2)
    lstOfString.Add(String3)
    lstOfString.Add(String4)
    

    If you're adding known values, as you show, a good option is to use something like:

    Dim inputs() As String = { "some value", _
                                  "some value2", _
                                  "some value3", _
                                  "some value4" }
    
    Dim lstOfString as List(Of String) = new List(Of String)(inputs)
    
    ' ...
    Dim s3 = lstOfStrings(3)
    

    This will still allow you to add items later as desired, but also get your initial values in quickly.


    Edit:

    In your code, you need to fix the declaration. Change:

    Dim lstWriteBits() As List(Of String) 
    

    To:

    Dim lstWriteBits As List(Of String) 
    

    Currently, you're declaring an Array of List(Of String) objects.

    0 讨论(0)
提交回复
热议问题