How to declare and initialize a multidimensional array in VB.NET?

I want to do this:

Dim Numbers As Integer()() = {{1}, {2}, {3}, {4, 5, 6, 7}} 

The IDE emphasizes 4, 5, 6, 7 and says Array initializer has 3 too many elements . What am I doing wrong?

+6
source share
1 answer

The following should work:

 Dim Numbers As Integer()() = {({1}), ({2}), ({3}), ({4, 5, 6, 7})} 

How documents are in Arrays in Visual Basic :

You can avoid the error when you supply nested array literals of different dimensions by inserting the literals of the internal array in parentheses. The brackets force the expression of the array literal to be evaluated, and the resulting values ​​are used with the literal of the external array

+11
source

All Articles