Consider these lines of code:
ConcurrentDictionary<string, object> error = new ConcurrentDictionary<string, object>();
error.Add("hello", "world"); //actually throws a compiler error
and
IDictionary<string, object> noError = new ConcurrentDictionary<string, object>();
noError.Add("hello", "world");
I eventually figure out that all you have to do is change the IL to make the Add
function private.
Now in the spirit of decoupled code I'd most likely use the Interface but it seems that Concurrent dictionary isn't too found of the Add
method.
Is it safe to really use Add
(I can't view the IL so I don't know if it's really thread safe.)? Or should I use the concrete type of ConcurrentDictionary<TKey, TValue>
and explicitly use TryAdd
.