X hits on this document





287 / 396

Chapter ‎18   Unsafe code

13. Interfaces

An interface defines a contract. A class or struct that implements an interface must adhere to its contract. An interface may inherit from multiple base interfaces, and a class or struct may implement multiple interfaces.

Interfaces can contain methods, properties, events, and indexers. The interface itself does not provide implementations for the members that it defines. The interface merely specifies the members that must be supplied by classes or structs that implement the interface.

13.1 Interface declarations

An interface-declaration is a type-declaration (§‎9.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 (§‎17), followed by an optional set of interface-modifiers (§‎13.1.1), followed by the keyword interface and an identifier that names the interface, optionally followed by an optional interface-base specification (§‎13.1.2), followed by a interface-body (§‎13.1.3), optionally followed by a semicolon.

13.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 interfaces defined within a class. It specifies that the interface hides an inherited member by the same name, as described in §‎10.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 (§‎3.5.1).

13.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

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.274

Document info
Document views1231
Page views1231
Page last viewedThu Jan 19 16:55:49 UTC 2017