C#中接口(interface)的理解
更新時間:2007年03月25日 00:00:00 作者:
.都是“虛的”不能被實例化,這也是接口中為什么不能包含字段--成員變量的原因。
2.正因為接口是虛的,所以接口內(nèi)的索引,屬性,時間等只能有聲明,而不能在接口內(nèi)實現(xiàn),具體如何實現(xiàn)是派生接口或者派生類的事。
3.都具有模板的性質,如果一個接口或者類從某一個接口繼承,它將自動具有被集成者的特征(包括索引,屬性,函數(shù),實踐等)。
4.接口支持多重繼承,而C#中,類之支持單一繼承,接口實際表示的是一種承載能力。
下面是接口的一個簡單定義:
interface
SampInterface1
{
string
this[ int index]
{
get;
set
}
event EventHandler Event;
void Find( int value );
//注意此處沒有
{
}
string Po
int
{
get;
set
}
}
上面的接口定義了一個索引this,一個實踐Event,一個方法Find和一個屬性Point.
public interface SampIneterface:SampIneterface1{
pravite int a=1;
void find (int value)
{
a+=value;
}
event EventHandler Event;
protected void onEvent()
{
if(Event=null)
{return Event(this.System.EventAgrs.Empty;)}
}
}
2.正因為接口是虛的,所以接口內(nèi)的索引,屬性,時間等只能有聲明,而不能在接口內(nèi)實現(xiàn),具體如何實現(xiàn)是派生接口或者派生類的事。
3.都具有模板的性質,如果一個接口或者類從某一個接口繼承,它將自動具有被集成者的特征(包括索引,屬性,函數(shù),實踐等)。
4.接口支持多重繼承,而C#中,類之支持單一繼承,接口實際表示的是一種承載能力。
下面是接口的一個簡單定義:
復制代碼 代碼如下:
interface
SampInterface1
{
string
this[ int index]
{
get;
set
}
event EventHandler Event;
void Find( int value );
//注意此處沒有
{
}
string Po
int
{
get;
set
}
}
上面的接口定義了一個索引this,一個實踐Event,一個方法Find和一個屬性Point.
復制代碼 代碼如下:
public interface SampIneterface:SampIneterface1{
pravite int a=1;
void find (int value)
{
a+=value;
}
event EventHandler Event;
protected void onEvent()
{
if(Event=null)
{return Event(this.System.EventAgrs.Empty;)}
}
}
相關文章
C#實現(xiàn)Excel轉PDF時設置內(nèi)容適應頁面寬度
將Excel轉為PDF格式時,通常情況下轉換出來的PDF頁面都是默認的寬度大小。所以本文提供了C#實現(xiàn)Excel轉PDF時設置內(nèi)容適應頁面寬度的示例代碼,需要的可以參考一下2022-04-04
C#實現(xiàn)DataTable數(shù)據(jù)行列轉換
這篇文章介紹了C#實現(xiàn)DataTable數(shù)據(jù)行列轉換的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-04-04

