Arrays in VB.NET

Posted Sat, Feb 16 2008 12:05 by bill

You probably know that declaring an array in VB, such as :

      Dim names(9) As String

creates an array with 10 elements.  As of VB8 you can use the 0 To syntax for the same thing:

      Dim names(0 To 9) As String

 

I prefer the 0 To syntax as it clearer for those from other languages as well as clearer for me ;)

 

But did you know you can also do this :

      Dim names(-1) As String

 

      Dim names(0 To -1) As String

this creates a zero length array.

This comes in handy if you are resizing an array, and there is the possibility of the count being zero, e.g

 

      Dim names(0 To count - 1) As String

 

 

:)

Filed under: , , ,