vb.net:index超出范围错误

l--*_*''' 0 vb.net

有人可以帮帮我吗.为什么会返回错误:

    Dim stuff As New System.Collections.ArrayList()
    Dim i As Integer
    i = 1

    Dim split As String() = temp_string.Split(",")
    For Each s As String In split
        If s.Trim() <> "" Then
            stuff(i) = s
            i = i + 1
        End If
    Next s
Run Code Online (Sandbox Code Playgroud)

东西(i)= 2行返回上述错误

eug*_*neK 5

使用stuff.Add(i)代替那个,你不是访问一个数组,而只是在创建后没有索引的列表,只有在分配值后才能访问它的索引作为数组.

  • +1.删除了我自己的(不正确的)帖子,并且我支持@eugeneK,显然他比我更好地阅读了这个问题. (2认同)