C# 多个接口

多种接口

要实现多个接口,请用逗号分隔它们:

实例

interface IFirstInterface 
{
  void myMethod(); // 接口方法
}

interface ISecondInterface 
{
  void myOtherMethod(); // 接口方法
}

// 实现多个接口
class DemoClass : IFirstInterface, ISecondInterface
{
  public void myMethod() 
  {
    Console.WriteLine("Some text..");
  }
  public void myOtherMethod() 
  {
    Console.WriteLine("Some other text...");
  }
}

class Program 
{
  static void Main(string[] args)
  {
    DemoClass myObj = new DemoClass();
    myObj.myMethod();
    myObj.myOtherMethod();
  }
}

亲自试一试