X hits on this document





138 / 396

Chapter ‎18   Unsafe code

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. Identical simple names and type names

In a member access of the form E.I, if E is a single identifier, and if the meaning of E as a simple-name (§‎7.5.2) is a constant, field, property, local variable, or parameter with the same type as the meaning of E as a type-name (§‎3.8), then both possible meanings of E are permitted. The two possible meanings of E.I are never ambiguous, since I must necessarily be a member of the type E in both cases. In other words, the rule simply permits access to the static members and nested types of E where a compile-time error would otherwise have occurred. 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 Color

void F() { Color = Color.Black; // References Color.Black static member Color = Color.Complement();// Invokes Complement() on Color field }

static void G() { Color c = Color.White;// References Color.White static member } }

Within 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.

7.5.5 Invocation expressions

An invocation-expression is used to invoke a method.

invocation-expression: primary-expression   (   argument-listopt   )

The primary-expression of an invocation-expression must be a method group or a value of a delegate-type. If the primary-expression is a method group, the invocation-expression is a method invocation (§‎ If the primary-expression is a value of a delegate-type, the invocation-expression is a delegate invocation (§‎ If the primary-expression is neither a method group nor a value of a delegate-type, a compile-time error occurs.

The optional argument-list (§‎7.4.1) provides values or variable references for the parameters of the method.

The result of evaluating an invocation-expression is classified as follows:

If the invocation-expression invokes a method or delegate that returns void, the result is nothing. An expression that is classified as nothing cannot be an operand of any operator, and is permitted only in the context of a statement-expression (§‎8.6).

Otherwise, the result is a value of the type returned by the method or delegate. Method invocations

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.125

Document info
Document views533
Page views533
Page last viewedMon Oct 24 20:22:28 UTC 2016