user987316
user987316

Reputation: 942

Define Dictionary of Dictionary in VB

In my VB code I am declaring my variable as below

Private m_IntegrationsAttribute As New Dictionary(Of String, Dictionary(Of String, String)) From {{"PrimeKey", {{"SubKey", ""}}}}

But I am getting error message as "Error 205 Value of type '2-dimensional array of String' cannot be converted to 'System.Collections.Generic.Dictionary(Of String, String)"

Can somebody suggest correct way of declaring variable for dictionary of dictionary?

Upvotes: 1

Views: 271

Answers (1)

sloth
sloth

Reputation: 101162

You should use

private m_IntegrationsAttribute As New Dictionary(Of String, Dictionary(Of String, String)) From 
{
    {"PrimeKey", New Dictionary(Of String, String) From {{"SubKey", ""}}}
}

If you don't use the extra New Dictionary(Of String, String) From ... the compiler will interpred {{"SubKey", ""}} as String(,) because it's the array initializer syntax. That's what the compiler error tells you.

Upvotes: 1

Related Questions