mandelbrot
Centurion
Dear All,
Because of the way my current app works I've used an interface to supply basic details between objects. Obviously the data is common to all and key to the execution of the system.
If an object implements the interface then is it possible to cast an interface variable to an implementing object type?
For instance:
I've tried this (or something very similar) and cannot get it to work...
Any advice would be appreciated.
Regards,
Paul.
Because of the way my current app works I've used an interface to supply basic details between objects. Obviously the data is common to all and key to the execution of the system.
If an object implements the interface then is it possible to cast an interface variable to an implementing object type?
For instance:
Visual Basic:
Interface IPerson
Property Name() As System.String
Property Age() As Int32
Property Born() As System.DateTime
End Interface
Class Employee
Implements IPerson
...
Public Property Id() As Int32
Get
Return _Id
End Get
Set(ByVal Value As Int32)
_Id = Value
End Set
End Property
Public Property Name() As System.String Implements IPerson.Name
Get
Return _Age
End Get
End Property
...
End Class
...
Dim manager As IPerson = New Employee()
...
[color=red]MessageBox.Show("Employee " & DirectCast(manager, Employee).Id & " has been updated.", "Employee Updated")[/color]
Any advice would be appreciated.
Regards,
Paul.