VB.NET How to declare new empty array of known length VB.NET How to declare new empty array of known length arrays arrays

VB.NET How to declare new empty array of known length


The syntax of VB.NET in such a case is a little different. The equivalent of

string[] dest;// more code heredest = new string[src.Length];

is

Dim dest As String()' more code heredest = New String(src.Length - 1) {}


The normal way to do this would be to declare the array like so:-

Dim my_array() As String

and later in the code

ReDim my_array (src.Length - 1)


You can use Redim as already noted but this is the equivalent VB code to your C#

Dim dest As String()dest = New String(src.Length - 1) {}

Try and avoid using dynamic arrays though. A generic List(Of T) is much more flexible