Will Young

Will Young

  • NA
  • 1
  • 3k

Problems converting from derived to base class

Nov 4 2010 5:38 PM


I am trying to convert from a derived class to a base class and it kind of works.  Is there a way to get it to really work.  Take the following example:

Class A
   Public Description as String
End Class
Class B
   Inherits A
End Class
Function Test() As String
   Dim myB As B
   Dim obj As Object
   myB = New B()
   obj = CType(myB, A)
   return obj.GetType.ToString
End Function

In this case the tostring comes back as B not A.  For all other purposes it works, but it isn't actually converting it to class A.  This is only a problem because I have some Override methods I'm employing.
Any insight would be much appreciated.  I'm using VB.NET 2008 for reference.  Thanks.