SortDictionary but sort by Value
How do you SortDictionary by value (.NET 2.0)? Or is there any alternative to this?
I am trying to sort Tags just like in blogger. But I want to sort the Tags by number there were used, not by name?
I have to ask again .. why this code wont work when used in ASP.NET
result.Sort((first, second) => second.Value.CompareTo(first.Value));
it throws 5 errors while building
You can use a lambda function and a List to do something like:
var myList = new Dictionary<string, int>();
var result = new List<KeyValuePair<string, int>>(myList);
result.Sort((first, second) => second.Value.CompareTo(first.Value));
精彩评论