In VB6 you can do this:
Dim a As Variant
a = Array(1, 2, 3)
Can you do a similar thing in VB.NET with specific types, like so?:
Dim a() As Integer
a = Array(1, 2, 3)
Visual Basic Arrays Declaration In visual basic, Arrays can be declared by specifying the type of elements followed by the brackets () like as shown below. Dim array_name As [Data_Type](); Here, array_name represents the name of an array and Data_type will represent the data type of elements to store in an array.
Static and dynamic arraysStatic arrays must include a fixed number of items, and this number must be known at compile time so that the compiler can set aside the necessary amount of memory. You create a static array using a Dim statement with a constant argument: ' This is a static array.
Dynamic arrays are arrays that can be dimensioned and re-dimensioned as par the need of the program. You can declare a dynamic array using the ReDim statement. Syntax for ReDim statement − ReDim [Preserve] arrayname(subscripts)
In VB6 you have two different kinds of arrays, static and dynamic. A VB6 static array is defined by means of a DIM keyword that specifies lower and upper indexes, whereas a dynamic array is defined by means of a DIM keyword with empty parenthesis. Dim arr1(10) As Integer ' a static array.
Dim a() As Integer = New Integer() {1, 2, 3}
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