Results 1 to 5 of 5

Thread: How to design this class?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    How to design this class?

    I have a class called CBike

    Now I need a class that will act as a collection of bikes..

    I want to be able to use for... each and also to access bikes by


    mybikecollection.item(3).GetName <-- where getname is a property of CBike

    Which framework class should I inherit so that I can do all this? I need one that implements ICollection, and I want it to be pretty fast...

    Is it enough to make it like this:

    class CVehicleCOllection : inherits Collection

    end class


    os what enlse is needed?

    I need a collection that can store items of a specific type! If I make them an arraylist I need to convert from object to CBike.. I don't want to do that..


    kind regards

  2. #2
    Lively Member
    Join Date
    Aug 2002
    Location
    Outer space
    Posts
    97
    dim oCBikes as collection

    set CBikes as a public property .... and use the .Add .Count etc functions to access your collection

  3. #3
    Member leazfe's Avatar
    Join Date
    Mar 2004
    Location
    Spain
    Posts
    43
    I would do it by inherits CollectionBase.
    Something like this:
    Code:
    Public Class CVehicleCOllection 
        Inherits CollectionBase
        'The type-safe add method
        Sub Add(ByVal item As CBike)
            Me.List.Add(item)
        End Sub
        'Remove the specified object
        Sub Remove(ByVal item As CBike)
            Me.List.Remove(item)
        End Sub
        'Check that a given element is in the collection
        Function Contains(ByVal item As CBike) As Boolean
            Return Me.List.Contains(item)
        End Function
    You can also use the InnerList Object which is really usefull:
    Code:
     'Sort the item in the collection
        Sub Sort()
            Me.InnerList.Sort()
        End Sub
        'Return the index of a CBike element
        Function IndexOf(ByVal item As CBike) As Integer
            Return Me.InnerList.IndexOf(item)
        End Function
    End Class
    I hope it help you,
    Alvaro

  4. #4
    Lively Member
    Join Date
    Aug 2002
    Location
    Outer space
    Posts
    97
    cool

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Thanks for the code...

    What if I want to remove the entire collection from memory, which is the most efficient way to do it?

    mycol.Dispose() ?

    kind regards
    Henrik

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