3 ms·
Yes and probably make the most sense as .Net has no "undefined" value. If the dictionary has a the key with a null value it returns null, but no key throws. Wi
by SigmundA 7y ago
Yes and probably make the most sense as .Net has no "undefined" value. If the dictionary has a the key with a null value it returns null, but no key throws.
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.
- 7777fps 7y agoI often think it's a shame there isn't a "GetOrDefault" for dictionaries. 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.
- SigmundA 7y agoYes I agree, ImmutableDictionary has GetValueOrDefault, GetOrAdd is nice on ConcurrentDictionary and FirstOrDefault is nice in Linq.