欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#接口interface用法实例

程序员文章站 2023-11-12 23:54:40
本文实例讲述了c#接口interface用法。分享给大家供大家参考。具体如下: using system; //example of interfaces p...

本文实例讲述了c#接口interface用法。分享给大家供大家参考。具体如下:

using system;
//example of interfaces
public class animals
{
//simple interface
interface ianimal {
 void breathes();
}
//interfaces can inherent from other interfaces
interface imammal : ianimal {
 int hairlength();
}
//interfaces can implement other interfaces which implemented interfaces
interface imarsupial : imammal {
 int pouchsize();
}
//interfaces can implement many other interfaces
interface igonermammal : imammal, iextinct {
}
interface iextinct {
 int howlongextinct();
}
//classes can implement multiple interfaces
public class tasmaniantiger : igonermammal, imarsupial {
public int pouchsize() { return 2; }
public int howlongextinct() { return 28; }
public int hairlength() { return 4; }
public void breathes() { }
}
  public static void main(string[] args) {
 console.write("the tasmanian tiger has been extinct for {0} years", new tasmaniantiger().howlongextinct());
  }
}

希望本文所述对大家的c#程序设计有所帮助。