devoured elysium
devoured elysium

Reputation: 105067

Question about implicit operator overloading in c#

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

Upvotes: 2

Views: 313

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062745

Sure...

class MyClass
{
    public static implicit operator MyClass(int value) { /* your code */ }
}

Upvotes: 10

Related Questions