Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HashTables

Status
Not open for further replies.

slimroberts1

Programmer
Jan 30, 2003
5
IE
Can any one tell me if there is some sort of sorting in a hashtable. I load a table with key+value pairs and would like to see them come out in the same order. But they seem to be random. Has any one any ideas.
Many thanks
Slim
 
Sorry, one of the definitions of a HashTable is that order isn't important. Maybe if you used an ArrayList?

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
You are looking for the SortedList, which is functionally similar to the Hashtable, but it maintains the order in which items are added. It still allows the key-value addressing, as well as addressing by index.
 
Thanks for that I know that is what the book says, It also says that the order is as per adding order. But its not and I was wondering why not. The Arraylist I have been using and it works just fine. But as I need to fill a combo with a list of descriptions and when the user selects one get the code for that one I have had to use 2 array's one with code and one with description which is not the best way.
Many thanks
Slim
 
Hi,

I am very new to C# and haven't done much of the work on it Yet. But I think you can use an Object which takes in Key + Value and add the Object to ArrayList. While Display you can iterate over the ArrayList to get the Key + Value from the Object into the combo box.

Cheers,
Venu
 
Slimroberts1 -

Since ArrayList takes objects of type Object, you can create a very small (!) class with the two values you need to track, so that you only need one ArrayList.

Chip H.



If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top