The indexer into Dictionary throws an exception if the key is missing. Is there an implementation of IDictionary that instead will return de
Carrying these extension methods can help..
public static V GetValueOrDefault(this IDictionary dict, K key)
{
return dict.GetValueOrDefault(key, default(V));
}
public static V GetValueOrDefault(this IDictionary dict, K key, V defVal)
{
return dict.GetValueOrDefault(key, () => defVal);
}
public static V GetValueOrDefault(this IDictionary dict, K key, Func defValSelector)
{
V value;
return dict.TryGetValue(key, out value) ? value : defValSelector();
}