在c#3.0中,是否可以在字符串类中添加隐式运算符?
发布时间:2020-12-15 08:38:55 所属栏目:百科 来源:网络整理
导读:就像是 public static class StringHelpers{ public static char first(this string p1) { return p1[0]; } public static implicit operator Int32(this string s) //this doesn't work { return Int32.Parse(s); }} 所以: string str = "123";char oneLet
就像是
public static class StringHelpers { public static char first(this string p1) { return p1[0]; } public static implicit operator Int32(this string s) //this doesn't work { return Int32.Parse(s); } } 所以: string str = "123"; char oneLetter = str.first(); //oneLetter = '1' int answer = str; // Cannot implicitly convert ... 解决方法
不,没有扩展操作符(或属性等) – 只有扩展方法.
C#团队已经考虑过了 – 可以做各种有趣的事情(想象扩展构造函数) – 但它不是在C#3.0或4.0中.有关详细信息,请参阅Eric Lippert’s blog(与往常一样). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- flash 与 vb 也能交互啦!
- c – 如何破译指针数组的复杂声明?
- ERROR: relation "public.userinfo" doe
- ruby-on-rails – 将附加标题添加到Carrierwave
- ruby – 使用Middleman App构建时忽略文件夹
- react综合案例-todolist、localstorage缓存数据
- c# – WCF:在IErrorHandler中提供通用的FaultEx
- 对XML文件的解析,DOM、SAX、JDOM、JAXB还有dom4
- 如何在swift 2.0(iOS)中的单例类中创建可全局访问
- c – 将指向数据的指针作为参数传递给期望二维数
热点阅读