I have a hashtable with different words(key) and the number of times they occur(value).
I want to sort it based on value in such a way that the word which occurs for the most no. of times appears first.How do I do so?
Printable View
I have a hashtable with different words(key) and the number of times they occur(value).
I want to sort it based on value in such a way that the word which occurs for the most no. of times appears first.How do I do so?
Can you update the outdated hashtable into a generic collection like:
System.Collections.Generic.SortedDictionary<> or
System.Collections.Generic.Dictionary<> ?
This is impossible, it is not how a hashtable works. What you want to do is something like:
Assuming you have a Dictionary<K, V> you can do something like:
Dictionary<string, int> foo = GenerateDictionary ();
List<string> resultsInOrder = foo.OrderBy (k => k.Value).Select (k => k.Key).ToList ();
This will take all the KeyValuePairs in the dictionary, order them based on their value and finally select just the key component (the string part) and put them in a list.