Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET Empty String Array

How can I create an empty one-dimensional string array?

like image 815
YonahW Avatar asked Sep 04 '08 20:09

YonahW


1 Answers

VB is 0-indexed in array declarations, so seomthing like Dim myArray(10) as String gives you 11 elements. It's a common mistake when translating from C languages.

So, for an empty array, either of the following would work:

Dim str(-1) as String ' -1 + 1 = 0, so this has 0 elements Dim str() as String = New String() { } ' implicit size, initialized to empty 
like image 77
Mark Brackett Avatar answered Oct 12 '22 08:10

Mark Brackett