关闭

20.1 Interface declarations

596人阅读 评论(0) 收藏 举报
An interface-declaration is a type-declaration (§16.5) that declares a new
interface type.
interface-declaration:
attributesopt interface-modifiersopt interface identifier interface-baseopt
interface-body ;opt
An interface-declaration consists of an optional set of attributes (§24),
followed by an optional set of interfacemodifiers
(§20.1.1), followed by the keyword interface and an identifier that names
the interface, optionally
followed by an optional interface-base specification (§20.1.2), followed
by a interface-body (§20.1.3), optionally
followed by a semicolon.
20.1.1 Interface modifiers
An interface-declaration may optionally include a sequence of interface
modifiers:
interface-modifiers:
interface-modifier
interface-modifiers interface-modifier
interface-modifier:
new
public
protected
internal
private
It is a compile-time error for the same modifier to appear multiple times
in an interface declaration.
The new modifier is only permitted on nested interfaces. It specifies that
the interface hides an inherited member
by the same name, as described in §17.2.2.
The public, protected, internal, and private modifiers control the
accessibility of the interface.
Depending on the context in which the interface declaration occurs, only
some of these modifiers may be
permitted (§10.5.1).
20.1.2 Base interfaces
An interface can inherit from zero or more interfaces, which are called the
explicit base interfaces of the
interface. When an interface has one or more explicit base interfaces, then
in the declaration of that interface, the
interface identifier is followed by a colon and a comma-separated list of
base interface identifiers.
interface-base:
: interface-type-list
The explicit base interfaces of an interface must be at least as accessible
as the interface itself (§10.5.4). [Note:
For example, it is a compile-time error to specify a private or internal
interface in the interface-base of a
public interface. end note]
C# LANGUAGE SPECIFICATION
280
It is a compile-time error for an interface to directly or indirectly
inherit from itself.
The base interfaces of an interface are the explicit base interfaces and
their base interfaces. In other words, the
set of base interfaces is the complete transitive closure of the explicit
base interfaces, their explicit base
interfaces, and so on. An interface inherits all members of its base
interfaces. [Example: In the example
interface IControl
{
void Paint();
}
interface ITextBox: IControl
{
void SetText(string text);
}
interface IListBox: IControl
{
void SetItems(string[] items);
}
interface IComboBox: ITextBox, IListBox {}
the base interfaces of IComboBox are IControl, ITextBox, and IListBox. In
other words, the IComboBox
interface above inherits members SetText and SetItems as well as Paint. end
example]
A class or struct that implements an interface also implicitly implements
all of the interface?s base interfaces.
20.1.3 Interface body
The interface-body of an interface defines the members of the interface.
interface-body:
{ interface-member-declarationsopt }
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:566355次
    • 积分:11489
    • 等级:
    • 排名:第1351名
    • 原创:565篇
    • 转载:0篇
    • 译文:0篇
    • 评论:50条
    文章分类