Click here to Skip to main content
15,908,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i make a hastable like this

Hashtable Al = new Hashtable();
Al.Add("C100", "Carolla");
Al.Add("C200", "BMW");
Al.Add("C300", "Aulto");
Al.Add("C400", "Civic");

and its output is:

C100, Carolla
C200, BMW
C300, Aulto
C400, Civic

and i want to sorting like this or else

C300, Aulto
C200, BMW
C400, Civic
C100, Carolla

plz help me
Posted

Hashtable Al = new Hashtable();
Al.Add("C100", "Carolla");
Al.Add("C200", "BMW");
Al.Add("C300", "Aulto");
Al.Add("C400", "Civic");

List<string> cars = new List<string>(Al.Values);
cars.Sort();
 
Share this answer
 
v2
Hashtables exist to map keys to values. Implicit in this mapping is the concept that the keys aren't sorted or stored in any particular order. So there is no way to sort a Hashtable by Value.

You would probably be better off using a SortedDictionary[^] instead, as the alternative is to iterate the Hashtable and construct a new, sorted object from it.
 
Share this answer
 
have a look at this..
Sorting Hashtable[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900