Exemple #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>
 /// <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 IDictionary <TKey, TValue> dictionary, TKey key)
 {
     return(dictionary.GetOrDefault(key, default));
 }
Exemple #2
0
 /// <summary>
 /// Returns the value associated with the specified key, or a default value if no element is found.
 /// </summary>
 /// <typeparam name="TKey">The key data type</typeparam>
 /// <typeparam name="TValue">The value data type</typeparam>
 /// <param name="source">The source dictionary.</param>
 /// <param name="key">The key of interest.</param>
 /// <returns>The value associated with the specified key if the key is found, the default value for the value data type if the key is not found</returns>
 public static TValue GetOrDefault <TKey, TValue>(this IDictionary <TKey, TValue> source, TKey key)
 {
     return(source.GetOrDefault(key, default(TValue)));
 }
Exemple #3
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>
 /// <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 IDictionary <TKey, TValue> dictionary, TKey key) => dictionary.GetOrDefault(key, default(TValue));