CSharp examples for System.Collections.Generic:IDictionary
Get value from Dictionary with default value
using System.Reflection; using System.Text; using System.Linq; using System.Collections.Generic; using System;/* w w w. j a va 2 s.co m*/ public class Main{ public static V Get<K, V>(this Dictionary<K, V> dict, K key, V defaultValue = default(V)) { V value; if (!dict.TryGetValue(key, out value)) { value = defaultValue; } return value; } }