【发布时间】:2016-10-20 00:25:08
【问题描述】:
我想要一个字典,其中键是字符串 providerName,值是 categoryId 的集合。但是,这是我得到的结果:
看起来key只是item1、item2、item3等,value只是providerName,而categoryIds的集合根本不存在。
我的代码:
For i = 2 To Selection.Rows.Count
providerName = SingleLine(i, 1)
categoryId = SingleLine(i, 3)
Dim categoryIdCollection As New Collection
If Not providerNamesDictionary.exists(providerName) Then
categoryIdCollection.add (categoryId)
providerNamesDictionary.add key:=providerName, Item:=categoryIdCollection
Else
Dim tempCategoryIdCollection As Collection
Set tempCategoryIdCollection = providerNamesDictionary(providerName)
tempCategoryIdCollection.add (categoryId)
Set providerNamesDictionary(providerName) = tempCategoryIdCollection
End If
如何将键作为 providerName,将值作为 categoryIds 的集合?
【问题讨论】: