Two Classes one for Individual Item Another for a Collection of Items

  • Thread starter Thread starter slonocode
  • Start date Start date
S

slonocode

I am writing a class library. One class is Package and is basically
just the fields for the Package object. Another class is Packages and
is basically used to manage a collection of Package objects.

Could someone point me to some complete example code for this kind of
scenario?

Thanks
 
slonocode said:
I am writing a class library. One class is Package and is basically just
the fields for the Package object. Another class is Packages and is
basically used to manage a collection of Package objects.

Could someone point me to some complete example code for this kind of
scenario?

Thanks

Public Class Package_Collection

Inherits CollectionBase

Default Public Property Item(ByVal index As Integer) As Package

Get

Return CType(List(index), Package)

End Get

Set(ByVal Value As Package)

List(index) = Value

End Set

End Property

Public Function Add(ByVal value As Package) As Integer

Return List.Add(value)

End Function 'Add

Public Function IndexOf(ByVal value As Package) As Integer

Return List.IndexOf(value)

End Function 'IndexOf

Public Sub Insert(ByVal index As Integer, ByVal value As Package)

List.Insert(index, value)

End Sub 'Insert

Public Sub Remove(ByVal value As Package)

List.Remove(value)

End Sub 'Remove

Public Function Contains(ByVal value As Package) As Boolean

' If value is not of type Package, this will return false.

Return List.Contains(value)

End Function 'Contains

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top