J
J. Shane Kunkle
I took this example directly out of the book "Programming MS Visual
Basic.net" - they say this code works:
Class Person
Public FirstName As String
Public LastName As String
End Class
Class Employee
Inherits Person
Public Salary As Integer
End Class
Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim p As New Person
p.FirstName = "Ralph"
p.LastName = "X"
Dim emp As Employee = DirectCast(p, Employee) ' Exception When This
Line Executes
emp.Salary = 1000
End Sub
When i try to cast the base to the inherited class i get a
"System.InvalidCastException: Specified cast is not valid."
The book says specifically that this code should execute fine so i think i
am missing something small - any ideas?
Thanks in advance,
J. Shane Kunkle
(e-mail address removed)
Basic.net" - they say this code works:
Class Person
Public FirstName As String
Public LastName As String
End Class
Class Employee
Inherits Person
Public Salary As Integer
End Class
Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim p As New Person
p.FirstName = "Ralph"
p.LastName = "X"
Dim emp As Employee = DirectCast(p, Employee) ' Exception When This
Line Executes
emp.Salary = 1000
End Sub
When i try to cast the base to the inherited class i get a
"System.InvalidCastException: Specified cast is not valid."
The book says specifically that this code should execute fine so i think i
am missing something small - any ideas?
Thanks in advance,
J. Shane Kunkle
(e-mail address removed)