hashtable

  • Thread starter Thread starter frazer
  • Start date Start date
F

frazer

hi i have a hashtable which has some items in it.
when i enumerate it using the
IDictionaryEnumerator . it gives me the items in reverse order. why is
that. how do i correct it?

thnx
 
hi i have a hashtable which has some items in it.
when i enumerate it using the
IDictionaryEnumerator . it gives me the items in reverse order. why is
that. how do i correct it?

thnx

Hashtable stores the data in an internally determined order. You can
not rely on getting data out in the same order you put it in...

Maybe you might want to look into SortedList if you need to get your
values back in a certain order.
 
Tom said:
Maybe you might want to look into SortedList if you need to get your
values back in a certain order.

Why on earth Microsoft chose to call this object SortedList when it is a
hash is beyond me.

Hilton
 
Hilton said:
Why on earth Microsoft chose to call this object SortedList when it is a
hash is beyond me.

The SortedList isn't a hashtable - it's more like an ArrayList that
keeps itself sorted. The only way that it is similar to a Hashtable is
that it lets you access the values by key instead of only using an
integer index. It uses a binary search on the sorted array to do this,
not anything to do with hashes.

So it's implementation is very different from Hashtable, but it lets you
access the values by key. And if you iterate through the collection, it
comes back sorted by the keys. SortedList sounds like an OK name.

Sorry for the thread drift...
 
Back
Top