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
Looking around, and using some C# 3.0 features we can do this:
foreach (KeyValuePair item in keywordCounts.OrderBy(key=> key.Value)) { // do something with item.Key and item.Value }
This is the cleanest way I've seen and is similar to the Ruby way of handling hashes.