How to redefine the size of an existing array and reset the values in VB.NET

2 Answers

0 votes
Module Module1

    Sub Main()

        Dim array = New Integer() {23, 543, 1, 87, 818}

        Console.WriteLine(array(0))
        Console.WriteLine(array(1))
        Console.WriteLine(array(2))
        Console.WriteLine(array(3))
        Console.WriteLine(array(4))

        ReDim array(7)

        Console.WriteLine(array(3))
        Console.WriteLine(array(4))
        Console.WriteLine(array(5))
        Console.WriteLine(array(6))

    End Sub

End Module

' run:
' 
' 23
' 543
' 1
' 87
' 818
' 0
' 0
' 0
' 0

 



answered Aug 12, 2018 by avibootz
0 votes
Module Module1

    Sub Main()

        Dim array = New Integer() {23, 543, 1, 87, 818}

        Console.WriteLine(array(0))
        Console.WriteLine(array(1))
        Console.WriteLine(array(2))
        Console.WriteLine(array(3))
        Console.WriteLine(array(4))

        ReDim array(3)

        Console.WriteLine(array(1))
        Console.WriteLine(array(2))
        Console.WriteLine(array(3))

    End Sub

End Module

' run:
' 
' 23
' 543
' 1
' 87
' 818
' 0
' 0
' 0

 



answered Aug 12, 2018 by avibootz
...