SortDictionary, but sort by value

How do you SortDictionary by value (.NET 2.0)? Or is there an alternative to this?

I am trying to sort tags like in blogger. But I want to sort the tags by the number that was used, and not by name?


I have to ask again .. why this code does not work when used in ASP.NET

result.Sort((first, second) => second.Value.CompareTo(first.Value)); 

it gives 5 errors when building

+4
source share
1 answer

You can use the lambda function and 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)); 
+4
source

Source: https://habr.com/ru/post/1302699/


All Articles