max sharma wrote:
Hi all,
I am using hashtable in C# with keys of type string and values of type
double. I am not able to find a way to sort them by value (descending to
be precise) instead of key. Can someone please help me.
If you only need to sort once, something like:
string[] keys = new string[dict.Count];
dict.Keys.CopyTo(keys, 0);
double[] values = new double[dict.Count];
dict.Values.CopyTo(values, 0);
Array.Sort(values, keys);
If you need to access the data sorted by values while mutating the
hashtable you can implements your own datastructure which maintains: a
hash from string to double, and a sorted-list which maps the doubles to
strings. Be sure to delete the right values from the sorted-list if
duplicate doubles occur though.
--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music:
http://ungdomshus.nu <=-