VB Dynamic Arrays


Dynamic arrays are arrays that can be dimensioned and re-dimensioned as par the need of the program. You can declare a dynamic array using the ReDim statement.

Example

Module arraydc
Sub Main()
Dim marks()   As Integer
ReDim marks(2)
      marks(0) = 85
      marks(1) = 75
      marks(2) = 90
ReDim < Preserve marks(10)
      marks(3) = 80
      marks(4) = 76
      marks(5) = 92
      marks(6) = 99
      marks(7) = 79
      marks(8) = 75
 For i = 0   To, 10
          Console.WriteLine(i & vbTab & marks(i))
Next i
      Console.ReadKey()
End Sub
End Module
Output
0 85
1 75
2 90
3 80
4 76
5 92
6 99
7 79
8 75
9  0
10 0

Share this article on