Results 1 to 9 of 9

Thread: Better HashTable or Collection?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325

    Better HashTable or Collection?

    It's better to use HashTable or use Colection?

    Thx,
    Xmas79
    Learn, this is the Keyword...

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    For holding what?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Right answer... 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
    Learn, this is the Keyword...

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    array, hash, collection.....

    of course it also depends on how you plan to use these objects...

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    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
    Learn, this is the Keyword...

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Thanks nema! Your link made me understanding a lot of things!!!!!!!

    Best regards,
    Xmas79
    Learn, this is the Keyword...

  8. #8
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577
    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:
    1. Public Class Class1
    2.  
    3.     End Class
    4.  
    5.  
    6.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7.         Dim h As New Hashtable()
    8.  
    9.         Dim s As String = "String"
    10.         Dim p As Integer = 100
    11.  
    12.         Dim obj As New Class1()
    13.  
    14.         h.Add(s, "Blah.1")
    15.         h.Add(p, "Blah.2")
    16.         h.Add(obj, "Blah.3")
    17.  
    18.         MessageBox.Show(h.Item(s))
    19.         MessageBox.Show(h.Item(obj))

    notice how I have added 3 string values into the hastable, each with there own data type key.

  9. #9
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    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.
    Last edited by nemaroller; Aug 25th, 2003 at 05:20 PM.

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