类中的C#调用接口方法
发布时间:2020-12-15 19:59:02 所属栏目:百科 来源:网络整理
导读:interface ILol{ void LOL();}class Rofl : ILol{ void ILol.LOL() { GlobalLOLHandler.RaiseROFLCOPTER(this); } public Rofl() { //Is there shorter way of writing this or i is there "other" problem with implementation?? (this as ILol).LOL(); }}
interface ILol { void LOL(); } class Rofl : ILol { void ILol.LOL() { GlobalLOLHandler.RaiseROFLCOPTER(this); } public Rofl() { //Is there shorter way of writing this or i is there "other" problem with implementation?? (this as ILol).LOL(); } } 解决方法
您已经实现了接口
explicitly,通常您不需要这样做.相反,只需隐式实现它,并像任何其他方法一样调用它:
class Rofl : ILol { public void LOL() { ... } public Rofl() { LOL(); } } (注意您的实施也需要公开.) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |