20.1 Interface declarations

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 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值