using System;
using System.Collections.Generic;
using System.Text;
//显示接口实现
namespace interfaceDemo
{
public interface InterfaceA
{
void MethodA();//抽象方法
void MethodB();//
}
public interface InterfaceB
{
void MethodB();//抽象方法,与interfaceA接口方法同名
void MethodC();
}
public class ClassC : InterfaceA, InterfaceB
{
public void MethodA()//实现接口中的方法
{
Console.WriteLine("实现接口InterfaceA的MethodA方法");
}
public void MethodC()//实现接口中的方法
{
Console.WriteLine("实现接口InterfaceB的MethodC方法");
}
void InterfaceA.MethodB()//显示地指明实现的是那个接口的方法,注意不能有public
{
Console.WriteLine("实现接口InterfaceA的MethodB方法");
}
void InterfaceB.MethodB()//显示地指明实现的是那个接口的方法,注意不能有public
{
Console.WriteLine("实现接口InterfaceB的MethodB方法");
}
}
class ShowInterfaceImplement//测试类
{
static void Main(string[] args)
{
ClassC c = new ClassC();//实例化对象
c.MethodA();
c.MethodC();
//显示接口实现
InterfaceA interA=new ClassC();//接口通过实现接口的类进行实例化
interA.MethodB();//调用接口A的方法
InterfaceB interB=new ClassC();
interB.MethodB();//调用接口B的方法
Console.ReadLine();
}
}
}