How do you sort a dictionary object in C# 2.0 for asp.net or is their an alternative to Dictionay for sorting this is to sort a countries list alphabetically
views:
37answers:
3
+2
A:
You're looking for the SortedDictionary<TKey, TValue>
class, which will automatically sort itself by the key.
If you want to sort the values, you can use a List<string>
:
List<string> values = new List<string>(dict.Values);
values.Sort();
SLaks
2010-07-14 01:36:24
I just want countries list sorted and not the language code
littleMan
2010-07-14 01:40:13
What's in your dictionary?
SLaks
2010-07-14 01:42:26
A:
You may want to try a SortedList in System.Collections. There's also a generic version (System.Collections.Generic.SortedList).
Here's MSDN's link.
David Hoerster
2010-07-14 01:37:04