views:

37

answers:

3

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

+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
I just want countries list sorted and not the language code
littleMan
What's in your dictionary?
SLaks
+1  A: 

Use a SortedDictionary

Donnie
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