It's better to use HashTable or use Colection?
Thx,
Xmas79
Printable View
It's better to use HashTable or use Colection?
Thx,
Xmas79
For holding what?
Right answer... :o I supposed it depends on the object that I have to hold...
Give me a generic answer: for holding numbers only, strings only, my own classes and so on...
Thx,
Xmas79
array, hash, collection.....
of course it also depends on how you plan to use these objects...
What are the main difference between these container?
It's a speed problem? Memory usage?
For example I need one to hold my classes and that is fast...
And another thing: I saw that Collection is part of Microsoft.VisualBasic.dll, it's for compatibility only?
Tnx
Xmas79
http://www.microsoft.com/belux/nl/ms...lections1.mspx
I have been using strongly-typed collections derived from System.Collections.Collectionbase. How different it is from VisualBasic.Collections I don't know, probably not different in most respects, other than its not VB-specific.
Thanks nema! Your link made me understanding a lot of things!!!!!!!
Best regards,
Xmas79
A Hashtable is more more flexible.
Because the key can be anything, and not just a string as it is with a Collection.
Data is stored in a Collection in some kind of order, and you can add new items before or after other items. Well a Hashtable, there is no 'order', items are just added. So you don't specify where in the hashtable you should add new items, you simply just add them.
You can access the items using your key, remember the key can be any object, not just string
Sample code
VB Code:
Public Class Class1 End Class Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim h As New Hashtable() Dim s As String = "String" Dim p As Integer = 100 Dim obj As New Class1() h.Add(s, "Blah.1") h.Add(p, "Blah.2") h.Add(obj, "Blah.3") MessageBox.Show(h.Item(s)) MessageBox.Show(h.Item(obj))
notice how I have added 3 string values into the hastable, each with there own data type key.
A Hashtable is more more flexible.
Because the key can be anything, and not just a string as it is with a Collection.
Yes, but a collection class inherited from Systems.Net.Collectionbase can do the same. Obviously, you can do just about anything depending on how you want to implement.
I can have a collection of orders, pass in a collection of customers, and receive all orders pertaining to that collection of customers.
Additionally, you can add items in a collection by just doing a CustomerCollection.Add(someCustomer). Additional calls will put the additional customers after the first call, but if order is not important, it does not matter regardless.