|
-
Apr 30th, 2004, 03:08 AM
#1
Thread Starter
Frenzied Member
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
-
Apr 30th, 2004, 03:49 AM
#2
Lively Member
dim oCBikes as collection
set CBikes as a public property .... and use the .Add .Count etc functions to access your collection
-
Apr 30th, 2004, 03:55 AM
#3
Member
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
-
Apr 30th, 2004, 03:57 AM
#4
Lively Member
cool
-
Apr 30th, 2004, 04:45 AM
#5
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|