0

I have a dataset that I'm feeding into a hashtable:

Public Questions As Hashtable = New Hashtable        
Dim ds As DataSet = instCaisse.GetCaisseQuestions()

For i As Integer = 0 To (ds.Tables(0).Rows.Count - 1)
    Questions.Add(ds.Tables(0).Rows(i).Item("questionPart"),ds.Tables(0).Rows(i).Item("question"))
Next

When I feed the information from the database into my dataset (via stored procedure) everything is ordered alphabetically thanks to an order by in the stored proc's select statement.

When I load up the data from the hashtable, it appears unordered. Am I missing something, does hashtable do some sort of sorting that I'm not aware of?

In that respect I may end up just using a SortedList or a Dictionary to retain the ordering of the values. If that's the case which is the better option to use?

Him_Jalpert
  • 2,476
  • 9
  • 31
  • 55
  • possible duplicate of [Sorting Hashtable by Order in Which It Was Created](http://stackoverflow.com/questions/4080667/sorting-hashtable-by-order-in-which-it-was-created) – Matt Wilko Nov 26 '14 at 16:15
  • You should use a SortedDictionary instead of a HashTable in this instance – Matt Wilko Nov 26 '14 at 16:17
  • SortedDictionary would be the way to go. Also, next time, I would suggest you use Dictionary instead of Hashtable. – the_lotus Nov 26 '14 at 16:21
  • The question is why are you using a `Hashtable` in the first place? Do you need the fast lookup? – Magnus Nov 26 '14 at 17:59
  • I will just use a Dictionary for this then, but what's the difference between Dictionary and SortedDictionary, doesn't Dictionary already sort things? – Him_Jalpert Nov 26 '14 at 19:58

0 Answers0