I would like to initialize value to 0 if it does not already exists. Otherwise it should increment existing value.
ConcurrentDictionary<int, int> dic = new ConcurrentDictionary<int, int>();
dic.AddOrUpdate(1, 0, (key, old) => old++);
dic.AddOrUpdate(2, 0, (key, old) => old++);
At this point, dictionary has keys of 1 and 2 with value of 0 each.
dic.AddOrUpdate(1, 0, (key, old) => old++);
At this point for the key 1 the value should be 1 whereas for key 2 it should be 0, however, both have value of 0. Any idea why?