I want to do this:
Dim Numbers As Integer()() = {{1}, {2}, {3}, {4, 5, 6, 7}}
The IDE's underlining 4, 5, 6, 7
and saying Array initializer has 3 too many elements
. What am I doing wrong?
In visual basic, Multidimensional Arrays can be declared by specifying the data type of an elements followed by the brackets () with comma (,) separator. Following are the examples of creating two or three-dimensional arrays in visual basic programming language.
A multi-dimensional array can be termed as an array of arrays that stores homogeneous data in tabular form. Data in multidimensional arrays are stored in row-major order. The general form of declaring N-dimensional arrays is: data_type array_name[size1][size2]....
The following should work:
Dim Numbers As Integer()() = {({1}), ({2}), ({3}), ({4, 5, 6, 7})}
As documents in Arrays in Visual Basic:
You can avoid an error when you supply nested array literals of different dimensions by enclosing the inner array literals in parentheses. The parentheses force the array literal expression to be evaluated, and the resulting values are used with the outer array literal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With