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 SPECIFICATIONdeclaration, its name, and its type (§17.2.7.1, §17.2.7.2, §17.2.7.3). It is a compile-time error for a program todeclare a member whose signature matches one of these reserved signatures, even if the underlying runtimeimplementation does not make use of these reservations.The reserved names do not introduce declarations, thus they do not participate in member lookup. However, adeclaration’s associated reserved method signatures do participate in inheritance (§17.2.1), and can be hiddenwith the new modifier (§17.2.2).[Note: The reservation of these names serves three purposes:1. To allow the underlying implementation to use an ordinary identifier as a method name for get or setaccess to the <strong>C#</strong> language feature.2. To allow other languages to interoperate using an ordinary identifier as a method name for get or setaccess to the <strong>C#</strong> language feature.3. To help ensure that the source accepted by one conforming compiler is accepted by another, by makingthe specifics of reserved member names consistent across all <strong>C#</strong> implementations.end note]The declaration of a destructor (§17.12) also causes a signature to be reserved (§17.2.7.4).17.2.7.1 Member Names Reserved for PropertiesFor a property P (§17.6) of type T, the following signatures are reserved:T get_P();void set_P(T value);Both signatures are reserved, even if the property is read-only or write-only.[Example: In the exampleusing System;class A{public int P {get { return 123; }}}class B: A{new public int get_P() {return 456;}new public void set_P(int value) {}}class Test{static void Main() {B b = new B();A a = b;Console.WriteLine(a.P);Console.WriteLine(b.P);Console.WriteLine(b.get_P());}}a class A defines a read-only property P, thus reserving signatures for get_P and set_P methods. A class Bderives from A and hides both of these reserved signatures. The example produces the output:123123456end example]218

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

Saved successfully!

Ooh no, something went wrong!