xxxxxxxxxx
public static KeyValuePair<TKey, TValue> Max<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, Func<TValue, int> evaluateeProviderFunc)
{
if (dictionary == null || !dictionary.Any())
return default(KeyValuePair<TKey, TValue>);
var maxItemKey = dictionary.FirstOrDefault();
var max = 0;
foreach (var item in dictionary)
{
var m = evaluateeProviderFunc(item.Value);
if (m > max)
{
maxItemKey = item;
max = m;
}
}
return maxItemKey;
}