Thalecress
Thalecress

Reputation: 3451

How do I initialize a Dictionary(Of String, HashSet(Of String)) in VB.NET?

I've got an existing String and HashSet(Of String), but the following code

Dim myDict As New Dictionary(Of String, HashSet(Of String))(myString, myHashSet)

yields this Intellisense error: Argument matching parameter 'comparer' narrows from 'System.Collections.Generic.HashSet(Of String)' to 'System.Collections.Generic.IEqualityComparer(Of String)'

What's the right way to create this dictionary?

Upvotes: 3

Views: 2923

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564333

You can use a Collection Initializer:

Dim myDict As New Dictionary(Of String, HashSet(Of String)) From 
       {{myString, myHashSet}}

Upvotes: 7

Related Questions