A member access expression is declared as follows.
member-access:
primary-expression . identifier
predefined-type . identifier
predefined-type: one of
Boolean Byte Char Decimal Double Float
Integer Long Object SByte Short String
UInteger ULong UShort
A member access expression is in the form E.I where E is a primary expression or a standard type and I is an identifier, and it is calculated and classified as follows:
If E is a namespace and I is the name of an accessible member of that namespace, the result is that member and the expression is classified as a namespace or a type (depending on the member).
If E is a standard type or a primary expression classified as a type, and a member lookup of I in E produces a match, E.I is calculated and classified as follows:
If I identifies one or more methods, the result is this method group with no associated instance expression.
If I identifies a static property, the result is a property access with no associated instance expression.
If I identifies a static field:
If the field is read-only and the reference occurs outside the static constructor of the class or structure, in which the field is declared, the result is a value, namely the value of the static field I in E.
Otherwise, the result is a variable, namely the static field I in E.
If I identifies a static event:
If the reference to an event occurs within the class or structure, in which the event is declared, E.I is processed exactly as if I was a static field.
Otherwise, the expression result is an event access with no associated instance expression.
If I identifies a constant, the expression result is a value, namely the value of that constant.
If I identifies an enumeration member, the expression result is a value, namely the value of that enumeration member.
Otherwise, E.I is an invalid member reference, and a compilation error occurs.
If E is a property access, variable, or value, the type of which is T, and a member lookup of I in E produces a match, then E.I is calculated and classified as follows:
First, if E is a property, the value of the property is obtained and E is reclassified as a value.
If I identifies one or more methods, the result is a method group with an associated instance expression of E.
If I identifies an instance property, the result is a property access with an associated instance expression of E.
If T is a class and I identifies an instance property of that class type:
If the value of E is Null, System.NullReferenceException is thrown.
If the field is read-only and the reference occurs outside an instance constructor of the class in which the field is declared, the expression results in a value, namely the value of the field I in the object referenced by E.
Otherwise, the expression results in a variable, namely the field I in the object referenced by E.
If T is a structure and I identifies an instance property of this structure type:
If E is a value, or if the field is read-only and the reference occurs outside an instance constructor of the structure, in which the field is declared, the expression results in a value, namely the value of the field I in the structure instance referenced by E.
Otherwise, the expression result is a variable, namely the field I in the structure instance referenced by E.
If I identifies an event:
If the event reference occurs within the class or structure, in which the event is declared, the expression E.I is processed exactly as if it was an instance field.
Otherwise, the expression results in an event access with an associated instance expression.
Otherwise, E.I is an invalid member reference, and a compilation error occurs.
See also: