If I have a base class and two derived classes, and I want to implement the casting between the two derived classes by hand, is there any way to do that? (in C#)
<
You must implement a explicit or implicit operator.
class Imp_A : AbsBase { public static explicit operator Imp_B(Imp_A a) { Imp_B b = new Imp_B(); // Do things with b return b; } }
Now you can do the following.
Imp_A a = new Imp_A(); Imp_B b = (Imp_B) a;