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.

Chapter 14 Expressions• Otherwise, if the field is readonly and the reference occurs outside an instance constructor ofthe class in which the field is declared, then the result is a value, namely the value of the field Iin the object referenced by E.• Otherwise, the result is a variable, namely the field I in the object referenced by E.If T is a struct-type and I identifies an instance field of that struct-type:• If E is a value, or if the field is readonly and the reference occurs outside an instanceconstructor of the struct in which the field is declared, then the result is a value, namely thevalue of the field I in the struct instance given by E.• Otherwise, the result is a variable, namely the field I in the struct instance given by E.If I identifies an instance event:• If the reference occurs within the class or struct in which the event is declared, and the eventwas declared without event-accessor-declarations (§17.7), then E.I is processed exactly as if Iwas an instance field.• Otherwise, the result is an event access with an associated instance expression of E.• Otherwise, E.I is an invalid member reference, and a compile-time error occurs.14.5.4.1 Identical simple names and type namesIn a member access of the form E.I, if E is a single identifier, and if the meaning of E as a simple-name(§14.5.2) is a constant, field, property, local variable, or parameter with the same type as the meaning of E asa type-name (§10.8), then both possible meanings of E are permitted. The two possible meanings of E.I arenever ambiguous, since I must necessarily be a member of the type E in both cases. In other words, the rulesimply permits access to the static members and nested types of E where a compile-time error wouldotherwise have occurred. [Example: For example:struct Color{public static readonly Color White = new Color(…);public static readonly Color Black = new Color(…);public Color Complement() {…}}class A{public Color Color; // Field Color of type Colorvoid F() {Color = Color.Black;// References Color.Black staticmemberColor = Color.Complement();field}static void G() {member}}Color c = Color.White;// Invokes Complement() on Color// References Color.White staticWithin the A class, those occurrences of the Color identifier that reference the Color type are underlined,and those that reference the Color field are not underlined. end example]14.5.5 Invocation expressionsAn invocation-expression is used to invoke a method.invocation-expression:primary-expression ( argument-list opt )141

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

Saved successfully!

Ooh no, something went wrong!