문제

Is it possible to declare and initialize a ConcurrentDictionary? Maybe something like the Dictionary:

Dim Stuff = New ConcurrentDictionary(Of Integer, Integer) From {{0, 1}, {2, 3}}
도움이 되었습니까?

해결책

It looks like what you want is something like this:

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 can't use an initializer like the Dictionary since that method relies on having an Add method and ConcurrentDictionary only has AddOrUpdate.

다른 팁

Just use a Dictionary as an intermediate storage, and this constructor of ConcurrentDictionary:

Dim Stuff = New Dictionary(Of Integer, Integer) From {{0, 1}, {2, 3}}
Dim concurrentStuff = New ConcurrentDictionary(Of Integer, Integer)(Stuff)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top