【发布时间】:2014-05-27 12:07:42
【问题描述】:
我不确定如何编写ConcurrentDictionary.AddOrUpdate 方法的func 部分,即检查UpdatedOn 属性是否大于或等于现有键/值。
鉴于以下 POCO,当新项目的 DateTime 值大于时,我如何使用 .NET ConcurrentDictionary.AddOrUpdate 更新字典中的项目(如果存在)现有的...否则它只是添加它。
(伪代码)
var results = new ConcurrentDictionary<string, Foo>();
public class Foo
{
string Id;
string Name;
string Whatever;
DateTime UpdatedOn;
}
我一直是 looking at the 2nd overloaded method (AddOrUpdate(TKey, TValue, Func<TKey, TValue, TValue>)),只是不知道如何执行该方法的 Func 部分。
【问题讨论】:
-
您使用
ConcurrentDictionay的关键和价值是什么
标签: c# .net concurrentdictionary