1

I'd like to use VB.net to declare an array of 9 strings and give them some default values, but I'm getting an error with the following code. Any suggestions would be appreciated.

Code: Dim myWords(9) As String = {"a", "b", "c", "d", "e", "f", "g", "h", "i"}

Error: Explicit initialization is not permitted for arrays declared with explicit bounds.

1 Answer 1

3

The error if straight forward, don't declared the array with explicit bounds.

Dim myWords() As String = {"a", "b", "c", "d", "e", "f", "g", "h", "i"}

As Tim said, you can even do

Dim myWords = {"a", "b", "c", "d", "e", "f", "g", "h", "i"}
Sign up to request clarification or add additional context in comments.

2 Comments

or even more concise: Dim myWords = {"a", "b", "c", "d", "e", "f", "g", "h", "i"}
Yes. But what if I want to make sure that I gave just enough values for the size? Say months, weekdays, etc. To bad the compiler can't do that in one go.

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.