Public Class AClass
Protected MyProp as String
Public Sub New(ByVal AProp as String)
MyProp = AProp
End Sub
Public ReadOnly Property MyProperty() as String
Get
Return MyProp
End Get
End Property
End Class
Public Class AClass2
Inherits AClass
Protected MyProp2 as Int32
Public Sub New(ByVal AProp as String, AProp2 as Int32)
MyProp2 = AProp2
MyBase.New(AProp)
End Sub
Public ReadOnly Property MyProperty2() as Int32
Get
Return MyProp2
End Get
End Property
End Class
Module MainMod
Public Shared Sub Main()
Dim Cls1 as AClass
Dim Cls2 as AClass2
Console.Write("Creating Object")
Cls2 = New AClass2("Hello", 123)
Console.Write("Converting to it's base")
Cls1 = CType(Cls2, AClass)
Console.Write("Property MyProperty of AClass is: " & Cls1.MyProperty)
Console.Write("Turning Cls1 back into AClass2 using DirectCast")
Console.Write("Result of MyProperty2 is: " & [b][color=blue]DirectCast[/color][/b]([i]Cls1[/i], [u]AClass2[/u]).MyProperty2())
Console.Read()
End Sub
End Module