I have a method:
void foo(IDictionary<string, object> data) {
data["key1"] = getValue1();
data["key2"] = getValue2();
}
I currently call it as follows:
var serialDict = new Dictionary<string, object>();
foo(serialDict);
Now I need to call foo
with a ConcurrentDictionary
type because the dictionary is being populated on multiple threads.
var concurrentDict = new Dictionary<string, object>();
foo(concurrentDict);
Since ConcurrentDictionary
implements IDictionary
, I do not have to change the signature of the foo
method. And the change seems to work fine on my machine.
However, something doesn't sit well with me about being able to populate a regular dictionary and a concurrent dictionary in the same manner/method.
Is what I am doing safe?