6

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

2 Answers 2

11

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Yes using the below format:

Dim boolArr As Boolean() = New Boolean() {True, True, False, True}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.