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 here
dest = new string[src.Length];

is

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

Syntax note

When you use Visual Basic syntax to define the size of an array, you specify its highest index, not the total number of elements in the array. learn.microsoft.com

Example

These two array both have a length of 5:

C#:
string[] a = new string[5];
VB: 
Dim a As String() = New String(4) {}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)