
Originally Posted by
stanav
But the point is, when you declare an array, you must give it a size.
I know you know how arrays work but this terminology is wrong. You don't declare arrays. Just like any other type, you declare variables and create objects. Arrays are objects, i.e. instances of the Array class. This code declares a variable but does not assign an object to it, so the variable is Nothing:This code declares a variable, creates an object and assigns that object to the variable:
vb.net Code:
Dim obj As Object = New Object
VB provides the following shorthand for that code:The equivalent for arrays would be declaring a variable but creating no object, so the variable is Nothing:declaring a variable, creating an object and assigning the object to the variable:
vb.net Code:
Dim arr() As Object = New Object(upperBound) {}
and the VB shorthand:
vb.net Code:
Dim arr(upperBound) As Object
If we use the correct terminology all the time then the meaning is clear. To create an array object you must specify the number of elements. This makes perfect sense given that an array object cannot be resized. If you haven't specified the size of an array then you haven't created an object; you have just declared a variable.