【发布时间】:2015-02-06 16:47:10
【问题描述】:
用新值更新 ConcurrentDictionary 的正确方法是什么?我正在尝试 AllWidgets.TryUpdate(id, myWidget, myWidget) 并且它返回 false 并且在这种情况下无法正确更新:
Public Class Widget
Public ID As Integer
Public Name As String
Public Sub New(ByVal id As Integer, ByVal name As String)
ID = id
Name = name
End Sub
End Class
Dim AllWidgets As New ConcurrentDictionary(Of Integer, Widget)
AllWidgets.TryAdd(1, New Widget(1000, "Widget A"))
AllWidgets.TryAdd(2, New Widget(1001, "Widget B"))
Dim UpdateWidget As New Widget(1001, "Widget BB")
Dim IsUpdated As Boolean = AllWidgets.TryUpdate(2, UpdateWidget, UpdateWidget)
IsUpdated 为假
我想我真的不明白第三个参数应该如何用于复杂对象。
【问题讨论】:
标签: vb.net concurrentdictionary