How to: Determine the Size of an Array

The overall size of an array is the product of the lengths of all its dimensions. The array's Length property returns this overall size, which represents the total number of elements currently contained in the array, not the number of bytes they consume in storage.

To determine the total size of an array

  • Read the array's Length property. Do not follow the array name with parentheses.

    Dim thisDoubleArray(,) As Char = New Char(4, 9) {}
    MsgBox("Total length of thisDoubleArray is " & CStr(thisDoubleArray.Length))
    

    The MsgBox call displays "Total length of thisDoubleArray is 50".

You can find the length of each dimension from the array's GetLength method.

You can change the length of an individual dimension, which changes the overall size. However, you cannot change the rank (the number of dimensions).

See Also

Tasks

How to: Declare an Array Variable

How to: Create an Array

How to: Initialize an Array Variable

How to: Change the Size of an Array

How to: Determine the Length of One Dimension of an Array

Troubleshooting Arrays

Concepts

Array Size in Visual Basic

Reference

Length

Other Resources

Arrays in Visual Basic