Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual Basic
 Array Size Declaration for Visual B...
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Help for Visual Basic 6.0 Users
Array Size Declaration for Visual Basic 6.0 Users

Updated: November 2007

Visual Basic 2008 updates array size declaration for interoperability with the common language runtime.

In Visual Basic 6.0, you can specify the size of an array in its declaration, as in the following example:

Dim Month(0 To 11) As Integer

This causes the array to have a fixed size, which you cannot change with the ReDim statement.

In Visual Basic 2008, an array does not have a permanent size. The preceding example can be rewritten as either of the following declarations:

Visual Basic
Dim Month(11) As Integer   ' Reserves 12 elements -- (0) through (11).

Visual Basic
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:

Visual Basic
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.

Although an array's size can change in Visual Basic 2008, the number of dimensions must be fixed. The following example declares a three-dimensional array:

Visual Basic
Dim Point(,,) As Double

The ReDim statement can set or change the size of each dimension, but the array always remains three-dimensional.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker