13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 20 Interfaces20. InterfacesAn interface defines a contract. A class or struct that implements an interface must adhere to its contract. Aninterface 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 provideimplementations for the members that it defines. The interface merely specifies the members that must besupplied by classes or interfaces that implement the interface.20.1 Interface declarationsAn interface-declaration is a type-declaration (§16.5) that declares a new interface type.interface-declaration:attributes opt interface-modifiers opt interface identifier interface-base opt interface-body ; optAn 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, optionallyfollowed by an optional interface-base specification (§20.1.2), followed by a interface-body (§20.1.3), optionallyfollowed by a semicolon.20.1.1 Interface modifiersAn interface-declaration may optionally include a sequence of interface modifiers:interface-modifiers:interface-modifierinterface-modifiers interface-modifierinterface-modifier:newpublicprotectedinternalprivateIt 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 memberby 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 bepermitted (§10.5.1).20.1.2 Base interfacesAn interface can inherit from zero or more interfaces, which are called the explicit base interfaces of theinterface. When an interface has one or more explicit base interfaces, then in the declaration of that interface, theinterface identifier is followed by a colon and a comma-separated list of base interface identifiers.interface-base:: interface-type-listThe 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 apublic interface. end note]279

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!