C#完成兩接口中同名辦法實例剖析。本站提示廣大學習愛好者:(C#完成兩接口中同名辦法實例剖析)文章只能為提供參考,不一定能成為您想要的結果。以下是C#完成兩接口中同名辦法實例剖析正文
本文實例講述了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#法式設計有所贊助。