hello
Im using VB 2008
is it possible to set array items with one line code?
for example, can i do something like:
Dim array = Array("a", "b", "c", "d")
instead of:
Dim array()
array(0) = "a"
array(1) = "b"
array(2) = "c"
array(3) = "d"
thanks
You initialize an array variable by including an array literal in a New clause and specifying the initial values of the array. You can either specify the type or allow it to be inferred from the values in the array literal.
We can declare an array by specifying the data of the elements followed by parentheses () in the VB.NET. In the above declaration, array_name is the name of an array, and the Data_Type represents the type of element (Integer, char, String, Decimal) that will to store contiguous data elements in the VB.NET array.
All arrays must be zero-indexed. In Microsoft Visual Basic 6.0, you can define arrays with the lower bounds and upper bounds set to any integer. In Microsoft Visual Basic . NET, the lower bound of every array dimension is zero (0).
A parameter array can be used to pass an array of arguments to a procedure. You don't have to know the number of elements in the array when you define the procedure. You use the ParamArray keyword to denote a parameter array.
You can use the following to initialize an array with explicit members.
Dim array As String() = New String(){"a", "b", "c", "d"}
This can be done with any type.
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