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
LisaPosted Feb 17, 2009, 4:37 AM
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
Rohit KPosted Oct 26, 2008, 1:36 PM
Sunny ChenPosted Jul 4, 2008, 4:38 AM
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.
Mike GoldPosted Feb 28, 2008, 4:33 PM
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