I often have to sort a dictionary, consisting of keys & values, by value. For example, I have a hash of words and respective frequencies, that I want to order by frequen
On a high level, you have no other choice than to walk through the whole Dictionary and look at each value.
Maybe this helps: http://bytes.com/forum/thread563638.html Copy/Pasting from John Timney:
Dictionary s = new Dictionary();
s.Add("1", "a Item");
s.Add("2", "c Item");
s.Add("3", "b Item");
List> myList = new List>(s);
myList.Sort(
delegate(KeyValuePair firstPair,
KeyValuePair nextPair)
{
return firstPair.Value.CompareTo(nextPair.Value);
}
);