有关C#中隐式运算符重载的问题 [英] Question about implicit operator overloading in c#

查看:65
本文介绍了有关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;

谢谢

推荐答案

确定...

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

这篇关于有关C#中隐式运算符重载的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆