Coming from a C# background, I have no idea why the following declarationr returns an array with length = 2, can someone please enlighten me?
Dim lTestArray(1) As String
Console.WriteLine(lTestArray.Length) (writes 2)
Coming from a C# background, I have no idea why the following declarationr returns an array with length = 2, can someone please enlighten me?
Dim lTestArray(1) As String
Console.WriteLine(lTestArray.Length) (writes 2)
VB.NET array declarations supply the upper bounds (i.e. the maximum index) of the array, not the length. Since arrays are 0-based, a maximum index of 1 gives you two elements (0 and 1).
In VB.NET, you don't specify the length of the array... you actually specify the index of the last addressable element. Since .NET arrays are 0 based, and you specified 1 to be the last indexable element, the length is 2.