Beispiel #1
0
 /// <summary>
 /// Gets a value from the dictionary with given key. Returns default value if can not find.
 /// </summary>
 /// <param name="dictionary">Dictionary to check and get</param>
 /// <param name="key">Key to find the value</param>
 /// <param name="default"></param>
 /// <typeparam name="TKey">Type of the key</typeparam>
 /// <typeparam name="TValue">Type of the value</typeparam>
 /// <returns>Value if found, default if can not found.</returns>
 public static TValue GetOrDefault <TKey, TValue>(this IReadOnlyDictionary <TKey, TValue> dictionary, TKey key, TValue @default)
 {
     return(dictionary.TryGetValue(key, out var obj) ? obj : @default);
 }
Beispiel #2
0
 public static TValue GetValueOrDefault <TKey, TValue>(this IReadOnlyDictionary <TKey, TValue> dic, TKey key)
 {
     return(dic.TryGetValue(key, out TValue result) ? result ! : default !);