当前位置: 移动技术网 > IT编程>开发语言>c# > C#接口interface用法实例

C#接口interface用法实例

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了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#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网