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?
Printable View
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?
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.
and a HashTable IS a collection
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?
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.