本文实例讲述了c#实现两接口中同名方法。分享给大家供大家参考。具体分析如下:
对于一个类实现两个接口,而这两个接口又有同名方法,c#中的处理方式如下:
using system; using system.collections.generic; using system.text; namespace super { class program { static void main(string[] args) { superman sm = new superman(); sm.nightwork(); ((imoster)sm).create(); sm.dayword(); ((iperson)sm).create(); } } //妖的接口 interface imoster { void nightwork();//晚上工作的方法 void create();//晚上生育的方法 } //人的接口 interface iperson { void dayword();//白天工作的方法 void create();//白天生育的方法 } //超人 实现妖和人 两接口 class superman : imoster, iperson { #region imoster 成员 public void nightwork() { console.writeline("晚上工作"); } void imoster.create() { console.writeline("晚上生妖"); } #endregion #region iperson 成员 public void dayword() { console.writeline("白天工作"); } void iperson.create() { console.writeline("白天生人"); } #endregion } }
希望本文所述对大家的c#程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论