Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 796
devoured elysium Avatar asked Aug 29 '26 08:08

devoured elysium


1 Answers

Sure...

class MyClass
{
    public static implicit operator MyClass(int value) { /* your code */ }
}
like image 165
Marc Gravell Avatar answered Aug 31 '26 01:08

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!