ConcurrentDictionary — thread-safe. Dictionary — not thread-safe.
ConcurrentDictionary:
Dictionary:
1// ConcurrentDictionary2var dict = new ConcurrentDictionary<string, int>();3dict.TryAdd("key", 1);4dict.AddOrUpdate("key", 2, (k, v) => v + 1);56// Dictionary (with lock)7var dict = new Dictionary<string, int>();8lock (dict) { dict["key"] = 1; }
Key: ConcurrentDictionary for threads.