C# › Collections

When would you reach for a ConcurrentDictionary or an immutable collection?

Advanced

Answer

Use ConcurrentDictionary for thread-safe reads/writes without external locks; use ImmutableList/Dictionary when you want safe sharing across threads via copy-on-write snapshots.
var cache = new ConcurrentDictionary<int,User>();
cache.GetOrAdd(id, Load);
Real-world example A shared in-memory cache updated by many request threads uses ConcurrentDictionary.