Hi guys,
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?
Hi guys,
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?
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));
Thanks Thomas
Is this the correct way of enumerating the result?
foreach (KeyValuePair<string, int> pair in result) {Console.WriteLine(pair.Value);}
It's descending though so I used the result.Reverse();
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