C#中接口(interface)的理解

C#中的接口
1.都是“虚的”不能被实例化,这也是接口中为什么不能包含字段--成员变量的原因2.正因为接口是虚的,所以接口内的索引,属性,时间等只能有声明,而不能在接口内实现,具体如何实现是派生接口或者派生类的事.
3.都具有模板的性质,如果一个接口或者类从某一个接口继承,它将自动具有被集成者的特征(包括索引,属性,函数,实践等).
4.接口支持多重继承,而C#中,类之支持单一继承,接口实际表示的是一种承载能力,
下面是接口的一个简单定义:

interface
SampInterface1
{
    
string 
    
thisint 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;)}
}


}
posted @ 2006-09-23 18:17  释天  阅读(3422)  评论(1编辑  收藏  举报