oop - Cast of two custom types in VB.NET -


I need to put in better way, two types of custom-class (in VBnet):

< P> code:

  public class Pluto public sub-new (byVal as campoPippoPass string) _campoPippo = campoPippoPass End Sub string = "" public property campoPippo () string form as private _campoPippo Get back in the Me._campoPippo termination set (byVal as the value string) if not Object.Equals (Me._campoPippo, value) then Me._campoPippo = Original If the end ends, then end end of the end property ending class ending class public pippo public sub-new (byVal campoPippoPass as string) _campoPippo = campoPippoPass End Sub personal _campoPippo string = "" public property campoPippo () return as string Go to ._campoPippo End Set (ByVal Value as String) then go to Object.Equals (Me._campoPippo, valu E) Then Me._campoPippo = Set End End Price Ending End Property End Original Personal Button2_Click (ByVal This System. As an object I, as ByVal E System.EventArgs) manages the new pippo ("Ciao" as that Button2.Click dim a 'Here I have the error' invalid cast 'as the dim C Pluto = CTYPE (A, Pluto ) MsgBox (c.campoPippo) End Sub  

How do I change an "one" in the "C" object? Is there any other way than writing the following? New Pluto (a.campoPippo) as a slow C

In the case of more complex squares, if it has any function for conversion then more Can be easy.

First of all, I am assuming the line: in the form of dim C Pluto = CTYPE ( B, pluto) is a wrong type and in fact should be slow as in Pluto = CTYPE (A, Pluto)

You do not put one class in another unless they are related. You may need to explain that what you are trying to do otherwise my answer will be, why are you making different classes pluto and pippo if they are one Look similar? Just create a square and create two objects.

If you need different classes, then maybe they are related in some way and you can get from pippo Pluto ? Or both can apply the same interface.

In general I also suggest that it may be worth translating your class / variable names into English, because it can be easy for people to understand that you 're again Trying to do


Comments