Results 1 to 5 of 5

Thread: Hashtable -vs- Array/Collection?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382

    Hashtable -vs- Array/Collection?

    Is there any benifit in using a hashtable to store instances of classes rather than a collection or an arraylist/array? From what I can tell, a hashtable is a suped up version of an array? Is this right?

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Hashtable is a collection of keys and objects. When an object is inserted into a hashtable, it has to have a key. So if you wanted to get that object back, you would just provide the key and get the corresponding object.

    This cant be done in an Arraylist.
    Dont gain the world and lose your soul

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    and a HashTable IS a collection
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    Hmm, Ok so if a Hashtable "IS" a collection, how is the speed on a Hashtable? I'm wondering if a Hashtable would be suitable for storing TCPClient Connections in? There would be alot of enumeration in the Hashtable so would it be worth using it? Going back to the old VB6 days, Collections were heavily avoided because of its lack of speed but maybe that has changed in .Net? Can anyone confirm or deny this?

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    HashTable is still based on the CollectionBase, actually two of them (one for keys and one for values) so I don't think its any faster. I personally would just choose the easiest tool to work with because they are all collection based so I doubt you'd notice much of a speed difference.

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