In VB .NET, you cannot use an array's properties and methods until you instantiate it. For example, the following code declares an array. The two Debug.WriteLine statements that follow fail because the array has not been created.
Dim values() As Integer
Debug.WriteLine(values.Length)
Debug.WriteLine(values.GetLowerBound(0))
You can see if the array is Nothing to tell if it has been created yet.
Sometimes, however, the code would be more consistent if you could use Length, GetLowerBound, and GetUpperBound to loop over the empty array. You can do that if you use the following statement to allocate the array with no items in it.
Dim values(-1) As Integer
Now the array exists, Length returns 0, GetLowerBound returns 0, and GetUpperBound returns -1.
|