Results 1 to 3 of 3

Thread: sort hashtable

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2007
    Posts
    694

    sort hashtable

    Hi,
    I have populated a hashtable called CacheHashTableForwards.
    This is how the hashtable gets populated:

    CacheHashTablesForwards.Add(IndexName, code)
    ...

    Now I would like to sort this data which is inside the Hashtable.

    Not sure if this is a good approach but I use an ArrayList to do this as follows:

    CacheHashTablesForwardsArraySorted = new ArrayList(CacheHashTablesForwards.Keys)

    As you can see, The sorted array does not contains the other column, i.e. code
    How can I properly sort using the arraylist.
    Thanks

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: sort hashtable

    Why would you want to sort a Hashtable? The HashTable is basically a linked list. You should be able to access objects directly via the key object instead of any kind of iteration so I'm not sure why you would ever need to sort it. Maybe a HashTable is not the right tool for the job.

    Please explain further.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: sort hashtable

    If you want your collection sorted on the keys then a SortedList is preferable to a Hashtable. In .NET 2.0 you can use a generic SortedList or SortedDictionary.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width