20.1 Interface declarations

来源:互联网 发布:洪仔排课软件破解版 编辑:程序博客网 时间:2024/06/18 17:56
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 }
原创粉丝点击