DictionaryExtensions.cs 606 B

123456789101112131415161718
  1. using System.Collections.Generic;
  2. namespace MonoGame.Extended.Collections
  3. {
  4. public static class DictionaryExtensions
  5. {
  6. public static TValue GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key)
  7. {
  8. return GetValueOrDefault(dictionary, key, default(TValue));
  9. }
  10. public static TValue GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
  11. {
  12. TValue value;
  13. return dictionary.TryGetValue(key, out value) ? value : defaultValue;
  14. }
  15. }
  16. }