1. 把两个DICTIONARY 叠加在一起。并且返回DICTIONARY.
2. 给DICTIONARY的VALUE排序。
我从GOOGLE上找不到现成的, 只好花时间写了两段。希望节约大家的时间。
public static Dictionary<TKey, TValue> UnionDictionary<TKey, TValue>
(this Dictionary<TKey, TValue> first, Dictionary<TKey, TValue> second)
{
Dictionary<TKey, TValue> Rtn = new Dictionary<TKey, TValue>();
var collection = first.Union(second);
foreach (var item in collection)
{
Rtn.Add(item.Key, item.Value);
}
return Rtn;
}
public static Dictionary<TKey, TValue> SortByValue<TKey, TValue>(this Dictionary<TKey, TValue> dic)
{
Dictionary<TKey, TValue> Rtn = new Dictionary<TKey, TValue>();
var collection = dic.OrderBy(item => item.Value);
foreach (var item in collection)
{
Rtn.Add(item.Key, item.Value);
}
return Rtn;
}