Export (0) Print
Expand All Identical simple names and type names

Visual Studio .NET 2003

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 (Section 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 (Section 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.

© 2014 Microsoft