- Paddy.
]]>Do you mean:
”
When you expect to look up undefined keys
”
- Paddy.
]]>This is an interesting post. There’s some minor things I could debate, but overall, not a bad analysis. In the end, I believe .NET got this part of the interface mostly correct. There’s no unsafe corner cases to be aware of (beyond the debate about null values, which I find to be a pointless debate). TryGetValue allows you to optimally attempt to get a value (this isn’t so much about being an atomic operation, which in fact is not the case for Dictionary, but about not requiring two expensive lookups by using Contains followed by indexing). The only real complaint with TryGetValue is that it’s usage is overly verbose, and in many cases a GetValue such as you provided would be simpler to consume. I’d argue, though, that an interface without TryGetValue would be even less optimal then an interface without GetValue.
]]>