Don't .NET dictionaries throw when a requested key isn't found?
I think this design is the best one. It lets you have the program blow up quickly in all cases where the presence of the key is a requirement for the program to be in a valid state (which is common). Otherwise you'd be doing
x = dict[key]
if (x == null)
throw("Unexpected this is. And unfortunate");With generic dictionaries (which everyone uses now days) you have TryGetValue which is a little weird since it uses a out parameter but pretty natural after c# 7 inline out params.
An extension like
> dict<k,v>.GetOrDefault(k key,v valueIfNotPresent)
Would be really helpful. It's easy enough to write your own extension to do this, but something built in would be the kind of nice to have method that has been creeping into .net.