Currently I\'m using
var x = dict.ContainsKey(key) ? dict[key] : defaultValue
I\'d like some way to have dictionary[key] return null for nonexi
You can use a helper method:
public abstract class MyHelper { public static V GetValueOrDefault( Dictionary dic, K key ) { V ret; bool found = dic.TryGetValue( key, out ret ); if ( found ) { return ret; } return default(V); } } var x = MyHelper.GetValueOrDefault( dic, key );