Invalid Cast Exceptions with Implicit Operators
public class TestClass
{
private MainClass MyMainClassObject;
public TestClass()
{
MyMainClassObject = new MainClass();
}
public static implicit operator MainClass(TestClass Source)
{
return Source.MyMainClassObject;
}
}
public class MainClass
{
public static void Main()
{
object MyObject;
MainClass MyMainClassObject;
MyObject = new TestClass();
MyMainClassObject = (MainClass)MyObject;
}
}
Related examples in the same category