using System.Collections.Generic; namespace Plane.Collections { public static class DictionaryExtensions { /// /// 尝试返回字典中与指定的键对应的值,若此键不存在则返回指定的默认值。 /// /// 键的类型。 /// 值的类型。 /// 源字典。 /// 键。 /// 默认值。 /// 若字典中包含指定的键,返回其对应的值;否则返回指定的默认值。 public static TValue GetValue(this Dictionary dictionary, TKey key, TValue defaultValue = default(TValue)) { var value = defaultValue; dictionary.TryGetValue(key, out value); return value; } } }