Redim statement of Array in vb.net

We can change the size of an array after creating them. The ReDim statement assigns a completely new array object to the specified array variable. You use ReDim statement to change the number of elements in an array. See Code sample:

Public Class MainClass
    Shared Sub Main()

        Dim Months(5) As String

 

        Months(0) = “Jan”

        Months(1) = “Feb”

        Months(2) = “Mar”

        Months(3) = “Apr”

        Months(4) = “May”

        Months(5) = “Jun”

        ReDim Preserve Months(8)

        Months(6) = “Jul”

        Months(7) = “Aug”

        Months(8) = “Sep”

 

        For i As Integer = 0 To Months.Length – 1

            System.Console.WriteLine(Months(i).ToString())

        Next   

    End Sub
End Class