VB.NET Empty String Array

后端 未结 10 880
花落未央
花落未央 2021-01-07 17:56

How can I create an empty one-dimensional string array?

10条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-07 18:27

    VB is 0-indexed in array declarations, so seomthing like Dim myArray(10) as String gives you 11 elements. It's a common mistake when translating from C languages.

    So, for an empty array, either of the following would work:

    Dim str(-1) as String ' -1 + 1 = 0, so this has 0 elements
    Dim str() as String = New String() { } ' implicit size, initialized to empty
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题