13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C#</strong> LANGUAGE SPECIFICATIONparticularly useful when a class or struct implements an internal interface that is of no interest to a consumerof that class or struct.• Explicit interface member implementations allow disambiguation of interface members with the samesignature. Without explicit interface member implementations it would be impossible for a class or struct tohave different implementations of interface members with the same signature and return type, as would it beimpossible for a class or struct to have any implementation at all of interface members with the samesignature but with different return types.For an explicit interface member implementation to be valid, the class or struct must name an interface in its baseclass list that contains a member whose fully qualified name, type, and parameter types exactly match those ofthe explicit interface member implementation. [Example: Thus, in the following classclass Shape: ICloneable{object ICloneable.Clone() {…}int IComparable.CompareTo(object other) {…} // invalid}the declaration of IComparable.CompareTo results in a compile-time error because IComparable is notlisted in the base class list of Shape and is not a base interface of ICloneable. Likewise, in the declarationsclass Shape: ICloneable{object ICloneable.Clone() {…}}class Ellipse: Shape{object ICloneable.Clone() {…} // invalid}the declaration of ICloneable.Clone in Ellipse results in a compile-time error because ICloneable is notexplicitly listed in the base class list of Ellipse. end example]The fully qualified name of an interface member must reference the interface in which the member was declared.[Example: Thus, in the declarationsinterface IControl{void Paint();}interface ITextBox: IControl{void SetText(string text);}class TextBox: ITextBox{void IControl.Paint() {…}void ITextBox.SetText(string text) {…}}the explicit interface member implementation of Paint must be written as IControl.Paint. end example]20.4.2 Interface mappingA class or struct must provide implementations of all members of the interfaces that are listed in the base classlist of the class or struct. The process of locating implementations of interface members in an implementing classor struct is known as interface mapping.Interface mapping for a class or struct C locates an implementation for each member of each interface specified inthe base class list of C. The implementation of a particular interface member I.M, where I is the interface inwhich the member M is declared, is determined by examining each class or struct S, starting with C and repeatingfor each successive base class of C, until a match is located:286

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

Saved successfully!

Ooh no, something went wrong!