Question

MyClass c = 10;

Is there any way to make this code work? I know that through the implicit operator overloading you can get the opposite to work:

int i = instanceOfMyClass;

Thanks

Was it helpful?

Solution

Sure...

class MyClass
{
    public static implicit operator MyClass(int value) { /* your code */ }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top