0

是否可以声明和初始化 ConcurrentDictionary?也许像字典这样的东西:

Dim Stuff = New ConcurrentDictionary(Of Integer, Integer) From {{0, 1}, {2, 3}}
4

2 回答 2

1

看起来你想要的是这样的:

Dim Stuff As New ConcurrentDictionary(Of Integer, Integer) _
    ({
            New KeyValuePair(Of Integer, Integer)(1, 2),
            New KeyValuePair(Of Integer, Integer)(3, 4),
            New KeyValuePair(Of Integer, Integer)(5, 6)})

ConcurrentDictionary 不能使用像 Dictionary 这样的初始化程序,因为该方法依赖于 Add 方法,而 ConcurrentDictionary 只有 AddOrUpdate。

于 2014-02-01T05:46:44.947 回答
0

只需使用 Dictionary 作为中间存储,以及ConcurrentDictionary 的构造函数

Dim Stuff = New Dictionary(Of Integer, Integer) From {{0, 1}, {2, 3}}
Dim concurrentStuff = New ConcurrentDictionary(Of Integer, Integer)(Stuff)
于 2014-02-01T13:23:13.653 回答