December 2019
Intermediate to advanced
346 pages
9h 8m
English
ConcurrentDictionary<TKey,TValue> represents a thread-safe dictionary. It is used to hold key-value pairs that can be read or written in a thread-safe manner.
ConcurrentDictionary can be created as follows:
ConcurrentDictionary<int, int> concurrentDictionary = new ConcurrentDictionary<int, int>();
Items can be added to the dictionary as follows:
concurrentDictionary.TryAdd(i, i * i);string value = (i * i).ToString();// Add item if not exist or else updateconcurrentDictionary.AddOrUpdate(i, value,(key, val) => (key * key).ToString()); //Fetches item with key 5 or if not exist than add key 5 with value 25concurrentDictionary.GetOrAdd(5, "25");
Items can be removed from the dictionary as follows:
string ...
Read now
Unlock full access