In Visual Basic 2008, an array does not have a permanent size. The preceding example can be rewritten as either of the following declarations:
|
Dim Month(11) As Integer ' Reserves 12 elements -- (0) through (11).
|
|
Dim Month() As Integer = New Integer(11) {}
|
These declarations are equivalent. Each specifies an initial size, which you can change during execution with the ReDim statement. To initialize the elements, you can use the following syntax:
|
Dim Month() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
|
If you specify –1 for one of the dimensions, the array does not contain any elements. A ReDim statement can change an array back and forth between empty and nonempty.