Accessibility
If an accessor has an accessor-modifier, the accessibility domain (§3.5.2) of the accessor is determined using the declared accessibility of the accessor-modifier. If an accessor does not have an accessor-modifier, the accessibility domain of the accessor is determined from the declared accessibility of the property or indexer. The presence of an accessor-modifier never affects member lookup (§7.3) or overload resolution (§7.5.3). The modifiers on the property or indexer always determine which property or indexer is bound to, regardless of the context of the access. Once a particular property or indexer has been selected, the accessibility domains of the specific accessors involved are used to determine if that usage is valid: · If the usage is as a value (§7.1.1), the get accessor must exist and be accessible. · If the usage is as the target of a simple assignment (§7.17.1), the set accessor must exist and be accessible. · If the usage is as the target of compound assignment (§7.17.2), or as the target of the ++ or -- operators (§7.5.9, §7.6.5), both the get accessors and the set accessor must exist and be accessible. In the following example, the property A.Text is hidden by the property B.Text, even in contexts where only the set accessor is called. In contrast, the property B.Count is not accessible to class M, so the accessible property A.Count is used instead. class A public int Count { class B: A new public string Text { new protected int Count { class M An accessor that is used to implement an interface may not have an accessor-modifier. If only one accessor is used to implement an interface, the other accessor may be declared with an accessor-modifier: public interface I public class C: I
|