Updating fields of values in a ConcurrentDictionary

后端 未结 3 1425
执笔经年
执笔经年 2020-12-18 22:33

I am trying to update entries in a ConcurrentDictionary something like this:

class Class1
{
    public int Counter { get; set; }
}

class Test
{
    private          


        
3条回答
  •  别那么骄傲
    2020-12-18 23:30

    You can use the AddOrUpdate function.

    Here is how you can increment the current value by 1:

    dict.AddOrUpdate(key, 1, (key, oldValue) => oldValue + 1);
    

提交回复
热议问题