Invalid Cast Exceptions with Implicit Operators : stackalloc « Language Basics « C# / C Sharp






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

1.stackalloc Demo
2.Allocating Memory from the Stack
3.allocates 26 characters on the stack the for loop assigns alphabetic characters to each element
4.Use stackalloc to allocate memory for integer array