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 Interfaces• If S contains a declaration of an explicit interface member implementation that matches I and M, then thismember is the implementation of I.M.• Otherwise, if S contains a declaration of a non-static public member that matches M, then this member is theimplementation of I.M.A compile-time error occurs if implementations cannot be located for all members of all interfaces specified inthe base class list of C. The members of an interface include those members that are inherited from baseinterfaces.For purposes of interface mapping, a class member A matches an interface member B when:• A and B are methods, and the name, type, and formal parameter lists of A and B are identical.• A and B are properties, the name and type of A and B are identical, and A has the same accessors as B (A ispermitted to have additional accessors if it is not an explicit interface member implementation).• A and B are events, and the name and type of A and B are identical.• A and B are indexers, the type and formal parameter lists of A and B are identical, and A has the sameaccessors as B (A is permitted to have additional accessors if it is not an explicit interface memberimplementation).Notable implications of the interface-mapping algorithm are:• Explicit interface member implementations take precedence over other members in the same class or structwhen determining the class or struct member that implements an interface member.• Neither non-public nor static members participate in interface mapping.[Example: In the exampleinterface ICloneable{object Clone();}class C: ICloneable{object ICloneable.Clone() {…}public object Clone() {…}}the ICloneable.Clone member of C becomes the implementation of Clone in ICloneable because explicitinterface member implementations take precedence over other members. end example]If a class or struct implements two or more interfaces containing a member with the same name, type, andparameter types, it is possible to map each of those interface members onto a single class or struct member.[Example: For exampleinterface IControl{void Paint();}interface IForm{void Paint();}class Page: IControl, IForm{public void Paint() {…}}Here, the Paint methods of both IControl and IForm are mapped onto the Paint method in Page. It is ofcourse also possible to have separate explicit interface member implementations for the two methods. endexample]287

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

Saved successfully!

Ooh no, something went wrong!