The selected answer is correct. This is for user2535489 provider with the correct way to implement the idea that it has:
public static class DictionaryExtensions { public static TValue GetValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue fallback = default(TValue)) { TValue result; return dictionary.TryGetValue(key, out result) ? result : fallback; } }
which can then be used with:
Dictionary<string, int> aDictionary;
source share