0

I have a Dictionary(Of Integer, String()). When I add a new Key I want to add an empty array with a defined length to it, so I can add and use the values later on.

Dim myDict As New Dictionary(Of Integer, String())()
Dim auxData(24) As String

myDict.Add(177, auxData)

Is there any way to add a value to the Dictionary without need to use a variable to use in the value? Just declaring an empty string array directly, with a specified length.

Something like:

myDict.Add(177, New String(24))
2
  • What happens when you try that code? Commented Sep 4, 2013 at 9:51
  • @JonSkeet It tries to use the String constructor and return an error converting the integer to a char array. Commented Sep 4, 2013 at 10:00

1 Answer 1

3

Just add {} after the array.

myDict.Add(177, New String(24){})
Sign up to request clarification or add additional context in comments.

1 Comment

Worked like a charm, I don't know why I didn't try that. Thanks!

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.