开发者

vb.net: index was out of range error

开发者 https://www.devze.com 2022-12-09 13:07 出处:网络
can someone please help me. why does this return an error: Dim stuff As New System.Collections.ArrayList()

can someone please help me. why does this return an error:

    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

the st开发者_运维百科uff(i)=2 line is returning the mentioned error


Use stuff.Add(i) instead of that, you accessing not an array but a list which doesn't have an index upon creation only after you assign values you can access it's indexes as an array.


Looks like it could be an off by one error. What is i initialized to? 0 or 1?

0

精彩评论

暂无评论...
验证码 换一张
取 消