如何在VB.NET中初始化Dictionary(Of String,HashSet(Of String))?

时间:2013-09-27 21:19:25

标签: vb.net

我有一个现有的StringHashSet(Of String),但是以下代码

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

产生此Intellisense错误:Argument matching parameter 'comparer' narrows from 'System.Collections.Generic.HashSet(Of String)' to 'System.Collections.Generic.IEqualityComparer(Of String)'

创建此词典的正确方法是什么?

1 个答案:

答案 0 :(得分:4)

您可以使用Collection Initializer

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