Collection of classes

ddebono

Member
Joined
Nov 25, 2013
Messages
6
Programming Experience
5-10
Hi!

I'm using Visual Basic 2013

In VB6 I used a Collection to hold classes.

I want to do something like this (simple example):

Car.Wheel(0).pressure=1

In VB6 I defined a Collection and added the subclasses to this and then made a property for the sub class:

Public Property Get Wheel(lIndex As Long) As clsWheeltem Set Wheel = collWheels(lIndex)
Exit Property
End Property

Public Property Let Wheel(lIndex As Long, Subclass As clsWheelItem)
Set collWheels(lIndex) = Wheel(Lindex)
End Property

In .net I cannot get this to work. It states that it's readonly in the let statement.

What can I do in Basic .net to use indexed subclasses ?
 
You can keep collection objects in a List(Of T) where T represents the item type, and expose the collection object from container class as a ReadOnly property.
 
Very.Simple :)
    Public Class Wheel
        Public Property Pressure As Integer
    End Class

    Public Class Car
        Private _wheels As New List(Of Wheel)
        Public ReadOnly Property Wheels As List(Of Wheel)
            Get
                Return _wheels
            End Get
        End Property
    End Class
 
But this makes the Wheels readonly ?

I would like to write to the properties also
No, it makes the collection object readonly, the collection can't be removed from the Car object, and you can't put a different collection object in place of the existing one. The contents of the collection can be modified, adding/removing Wheel objects to it. The Wheel objects that is contained in the collection is unrelated to that property being readonly, they can be modified all you want.
 
Back
Top