|
-
March 27th, 2012, 11:10 AM
#1
How to sort a hashtable?
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?
-
March 27th, 2012, 01:06 PM
#2
Re: How to sort a hashtable?
Can you update the outdated hashtable into a generic collection like:
System.Collections.Generic.SortedDictionary<> or
System.Collections.Generic.Dictionary<> ?
-
March 28th, 2012, 04:02 AM
#3
Re: How to sort a hashtable?
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.
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|