|
-
Feb 2nd, 2008, 09:41 PM
#1
Thread Starter
Lively Member
collections vs hashtable
I noticed that you can insert an object into a collection with a key and also retrieve the object by the key. Does the retrieve by key function of a collection work the same as a hashtable? Is it slower or faster?
I plan to use sql to return data from a database already sorted and then put the data into a hashtable. The data is already pre-sorted. I just need the hashtable to be ordered by how the data is added.
Last edited by daemonk; Feb 2nd, 2008 at 09:57 PM.
-
Feb 2nd, 2008, 09:56 PM
#2
Re: collections vs hashtable
Do not use the Microsoft.VisualBasic.Collection class for anything. It is a hold-over from VB6 and basically exists for backward compatibility.
If you need any type of collection then use a class from the System.Collections namespace or, if you're using .NET 2.0 or later, the System.Collections.Generic namespace. If sorting is not required then you can use the standard Hashtable class or generic Dictionary class. If sorting is required you can use the standard SortedList class or generic SortedList and SortedDictionary classes.
I would suggest always using a generic collection in preference to a standard equivalent unless you're using .NET 1.x, where generics don't exist.
-
Feb 2nd, 2008, 10:03 PM
#3
Thread Starter
Lively Member
Re: collections vs hashtable
I edited my original post while you posted your reply.
I don't need sorting, but I do need it to be ordered by how the data is added to the hashtable. So I guess I should just implemented an ordered hashtable.
-
Feb 2nd, 2008, 10:14 PM
#4
Thread Starter
Lively Member
Re: collections vs hashtable
I just did some searches. How about an OrderedDictionary? That seems like it would suit my needs. Are there anything to be aware of using it?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|