c# 接口

从接口的本身看

1、接口不能包含字段。

2、接口方法不能有具体实现。

3、接口不能实例化。

从访问权限看

1、接口成员一定是公共的。

2、类实现接口中的成员必须是公共的、非静态的。

从继承上看

1、接口可以被多继承,自身也可多继承。

2、基类实现接口,子类继承该实现。

3、类的属性和索引器可以为接口上定义的属性或索引器定义额外的访问器。(显示接口实现则不可以!)

说明:

class MyClass : Interface1
{
public string name;

public string show
{
get { return name; }
set { name=value;} //这里类添加的
}

}


interface Interface1
{
string show{get;}
}

显示接口实现

class MyClass : Interface1
{
public string name;

string Interface1.show
{
get { return name; }
// set { name = value; } 此时不能有这个语句,显示接口实现会出错
}
}


interface Interface1
{
string show{get;}
}
posted on 2011-03-18 10:18  穆穆  阅读(268)  评论(2编辑  收藏  举报