public class Test { private static ConcurrentDictionary<string, int> testDictionary = new ConcurrentDictionary<string, int>(); public void test() { string _key = "a"; int _value = 0; int curValue = 1; testDictionary.TryAdd(_key, _value); testDictionary.AddOrUpdate(_key, _value, (key, value) => { return value = curValue; }); testDictionary.TryGetValue(_key, out int getValue); testDictionary.GetOrAdd("b", 2); } }
原文:https://www.cnblogs.com/cg-931210/p/9263414.html