C#接口interface用法實(shí)例
更新時(shí)間:2015年06月29日 14:41:50 作者:pythoner
這篇文章主要介紹了C#接口interface用法,實(shí)例分析了C#接口的基本使用方法,需要的朋友可以參考下
本文實(shí)例講述了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());
}
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#實(shí)現(xiàn)合并多個(gè)word文檔的方法
這篇文章主要介紹了C#實(shí)現(xiàn)合并多個(gè)word文檔的方法,是C#針對(duì)Word文檔操作的一個(gè)非常重要的技巧,需要的朋友可以參考下2014-09-09
C#使用foreach語(yǔ)句遍歷堆棧(Stack)的方法
這篇文章主要介紹了C#使用foreach語(yǔ)句遍歷堆棧(Stack)的方法,涉及C#操作foreach實(shí)現(xiàn)遍歷堆棧的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04
Jquery+Ajax+Json+存儲(chǔ)過程實(shí)現(xiàn)高效分頁(yè)
這篇文章主要介紹Jquery+Ajax+Json+存儲(chǔ)過程實(shí)現(xiàn)分頁(yè),需要的朋友可以參考下2015-08-08
詳解C#如何使用重載方法實(shí)現(xiàn)不同類型數(shù)據(jù)的計(jì)算
這篇文章主要為大家詳細(xì)介紹了C#如何使用重載方法實(shí)現(xiàn)不同類型數(shù)據(jù)的計(jì)算,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-02-02

