Common Type System—Mixed Mode Accessibility
Mixed Mode Accessibility (Language Feature)
Properties are composed of two bits of code: the getter and setter. As of C# 2.0, you can define these to
have separate levels of accessibility. Of course, this isn’t a change to the CTS—you could have previously
written this all in IL—but is an improvement for the C# language itself. For example, it’s quite common
to provide a public getter and a protected setter. The following syntax enables just that:
class PropertyExample { private int x; private int y; public int X { get { return x; } protected set { x = value; } } public int Y { get { return y; } protected set { y = value; } } }
Notice that the property declaration still has a default accessibility, while the setter has a more restrictive
accessibility declared right at the point where you say set.
|

