Use extension methods to extend the dictionary

public static class DictionaryExtension 
{ /// <summary>

/// try to get value according to Key, then get a direct return value, you do not get a direct return null
/// the this the Dictionary <TKEY, TValue> dict H to get the dictionary to express our dictionary value
///

public static Tvalue TryGet<Tkey, Tvalue>(this Dictionary<Tkey, Tvalue> dict, Tkey key)
{
    Tvalue value;
    dict.TryGetValue(key,out value);
    return value;

  }

}
The this keyword followed by the class, all objects of this class can use this method

Published an original article · won praise 0 · Views 40

Guess you like

Origin blog.csdn.net/xiejun822/article/details/104268413