There are two ways I\'ve assigned values to a existing key in a concurrent dictionary in my current project.
A. concurrentDictionary1[key] = value
;
They both call TryAddInternal
, so behave exactly the same**.
Update:
There is another difference. Here's the code from the indexer:
set
{
TValue tValue;
if (key == null)
{
throw new ArgumentNullException("key");
}
this.TryAddInternal(key, value, true, true, out tValue);
}
vs. from the method
while (!this.TryAddInternal(key, tValue, false, true, out tValue1));
So it appears there is a chance that the indexer will fail silently, whereas the method will continue trying until it succeeds. Hmm, some more in-depth analysis would be required to fully understand the differences between the two :/
Decompilers are still your friend.
**I derped.