Hi! Sorry if this question is very very basic.
I need to cast, in the better way, 2 objects of 2 types of 2 custom-classes (in VB.Net):
The code:
Public Class pluto
Public Sub New(ByVal campoPippoPass As String)
_campoPippo = campoPippoPass
End Sub
Private _campoPippo As String = ""
Public Property campoPippo() As String
Get
Return Me._campoPippo
End Get
Set(ByVal value As String)
If Not Object.Equals(Me._campoPippo, value) Then
Me._campoPippo = value
End If
End Set
End Property
End Class
Public Class pippo
Public Sub New(ByVal campoPippoPass As String)
_campoPippo = campoPippoPass
End Sub
Private _campoPippo As String = ""
Public Property campoPippo() As String
Get
Return Me._campoPippo
End Get
Set(ByVal value As String)
If Not Object.Equals(Me._campoPippo, value) Then
Me._campoPippo = value
End If
End Set
End Property
End Class
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim a As New pippo("ciao")
' here I have the error 'invalid cast'
Dim c As pluto = CType(a, pluto)
MsgBox(c.campoPippo)
End Sub
How can I convert "c" in an "a" type object? There is another way than writing this? Dim c As New pluto(a.campoPippo) In the case of more complex class, it could be more easy if there were a function for the conversion. Thank you! Pileggi