Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb 2008 set array items with one line code

Tags:

arrays

vb.net

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

like image 383
John Avatar asked May 05 '11 10:05

John


People also ask

How do you initialize an array of variables?

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.

How do you declare an array variable in VB net?

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.

Do arrays start at 0 or 1 VB?

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).

What are array parameters?

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.


1 Answers

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.

like image 183
detaylor Avatar answered Sep 29 '22 19:09

detaylor