C#中接口(interface)的理解
2008-02-25 21:11
330 查看
C#中的接口
1.都是“虚的”不能被实例化,这也是接口中为什么不能包含字段--成员变量的原因2.正因为接口是虚的,所以接口内的索引,属性,时间等只能有声明,而不能在接口内实现,具体如何实现是派生接口或者派生类的事.
3.都具有模板的性质,如果一个接口或者类从某一个接口继承,它将自动具有被集成者的特征(包括索引,属性,函数,实践等).
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;)}
}
}
src: /article/5737854.html
1.都是“虚的”不能被实例化,这也是接口中为什么不能包含字段--成员变量的原因2.正因为接口是虚的,所以接口内的索引,属性,时间等只能有声明,而不能在接口内实现,具体如何实现是派生接口或者派生类的事.
3.都具有模板的性质,如果一个接口或者类从某一个接口继承,它将自动具有被集成者的特征(包括索引,属性,函数,实践等).
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;)}
}
}
src: /article/5737854.html
相关文章推荐
- C#中接口(interface)的理解
- C#通俗理解接口(interface)
- C#中接口(interface)的理解
- C#.NET常见问题(FAQ)-interface接口如何理解
- C#中接口(interface)的理解
- C# interface 接口理解
- C#中接口(interface)的理解--接口概念的理解
- C#中接口(interface)的理解
- C#中接口(interface)的理解--接口概念的理解
- C#中接口(interface)的理解_C#教程
- C#中接口(interface)的理解_C#教程
- C#中接口(interface)的理解
- c# interface 的理解(工厂模式)简单实例
- (转帖)C#编程利器:接口(Interface)
- c#接口作用的深入理解
- C# 接口(Interface)
- C#接口interface用法实例
- C# interface(接口)
- C#接口作用的深入理解
- C# 关于接口与基类的理解(二者的区别)