Is there a way to have a class collection of inherited types be initialized?
For example, here is my code:
Public Class CamryCar
Property Name As String = "Camry"
Property Color As String
End Class
Public Class RedCamry
Inherits CamryCar
Sub New()
MyBase.New()
Color = "Red"
End Sub
End Class
Public Class BlueCamry
Inherits CamryCar
Sub New()
MyBase.New()
Color = "Blue"
End Sub
End Class
What I'm doing today for a colllection is:
Public Class Camrys
Property Cars As New List(Of CamryCar) From {New RedCamry, New BlueCamry}
End Class
But this gives me an extra property of Cars
.
I can also do this:
Public Class Camrys
Inherits List(Of CamryCar)
End Class
I prefer this one as I don't have an extra property to deal with. But I can find a way to initialize that that list with objects of RedCamry
and BlueCamry
.
Is it impossible or is there another way to do this?