I have a question regarding hashtable.
I have a DataBase Table which has three column.
one is the sequence no, then two data fields.
Now I want to populate the hashtable in the same order as it is in the database .The order is very important here.
Then I want the HashTable to search for a particular key and get the value of the next item in the order(not the value of the key item but the next). How can this be done ?
Advice needed.
Thanks
Loading

Mike GoldRank #50 · 30.6K reputationPosted Feb 28, 2008, 11:33 AM EST
Hashtables don't have an order and you can't force an order on them either. Why not use a DataTable with datarows? The datarows map to your database and are in order. You can use the Select method in the DataTable to find your key, and then just add 1 to the row element to get the next one. If you want to use a "sorted hashtable" you can use a SortedDictionary which is kind of a cross between a hashtable and a sorted list.
http://www.c-sharpcorner.com/UploadFile/mgold/SortedDictionarySample06202007142815PM/SortedDictionarySample.aspx
Sunny Chen162 reputationPosted Jul 4, 2008, 12:38 AM EDT
Hashtables indeed doesn't provide sorting because it has its own way arranging the elements within it so that it can access the elements in the fastest way. This is one functionality that hash provides except digital signing.
In your scenario I think you can use the ArrayList which has a built-in method called Sort. Declare a class which implements the IComparer interface to define your sorting logic.
Rohit K29 reputationPosted Oct 26, 2008, 9:36 AM EDT
LisaRank #8,652 · 218 reputationPosted Feb 16, 2009, 11:37 PM EST
hash tables only support key value pairs u cant give them an explicit order to hold
its better if you can take a data table or array list instead of a hash table
Thanks,
Lisa