The ConcurrentDictionary documentation says the following:
It is a thread-safe collection of key / value pairs, which can be access to multiple threads at the same time.
Now when I read this, it seems to me that I can call any method in the ConcurrentDictionary API, and it will be thread safe ... but it also meant including explicit implementations, do I have this guarantee?
My example: if I want an atom operation to remove an element from ConcurrentDictionary if its value is some value.
So I can do this:
var concurrentDictionary = new ConcurrentDictionary<string, string>();
concurrentDictionary.TryAdd("hey", "ho");
((ICollection<KeyValuePair<string, string>>) concurrentDictionary).Remove(new KeyValuePair<string, string>("hey", "ho"));
, , , API ConcurrentDictionary , ... , , -, .
:
public static boolean TryRemove(this ICollection<KeyValuePair<TKey, TValue>> collection, TKey key, TValue value)
{
return collection.Remove(new KeyValuePair<TKey, TValue>(key, value));
}
Intellisense ConcurrentDictionary, ICollection, , - ( - ?!)
EDIT:
, " ", , ConcurrentDictionary . , , , , , , .