M
Marina
Hi,
Let's say I have 2 classes, one of which is inheriting from the other.
I also have a generic class.
When I declare an instance of the generic class, I want to be able to cast a
generic declaration of the child class as the base class.
I have an example below, and the last line in TestSub does not compile.
Since Class2 IS a Class1, I want to be able to make that assignment, and
treat my collection of Class2 objects as Class1 objects if I want, since
after all, that is what they are.
How do I go about making this work? Is it event possible?
Public Class Class1
End Class
Public Class Class2
Inherits Class1
End Class
Public Class CollectionClass(Of someType)
End Class
Public Class TestClass
Public Sub TestSub()
Dim t1 As CollectionClass(Of Class1)
Dim t2 As New CollectionClass(Of Class2)
t1 = t2
End Sub
End Class
Let's say I have 2 classes, one of which is inheriting from the other.
I also have a generic class.
When I declare an instance of the generic class, I want to be able to cast a
generic declaration of the child class as the base class.
I have an example below, and the last line in TestSub does not compile.
Since Class2 IS a Class1, I want to be able to make that assignment, and
treat my collection of Class2 objects as Class1 objects if I want, since
after all, that is what they are.
How do I go about making this work? Is it event possible?
Public Class Class1
End Class
Public Class Class2
Inherits Class1
End Class
Public Class CollectionClass(Of someType)
End Class
Public Class TestClass
Public Sub TestSub()
Dim t1 As CollectionClass(Of Class1)
Dim t2 As New CollectionClass(Of Class2)
t1 = t2
End Sub
End Class