logo
CSharp_Prog_Guide

Ограничения модификаторов доступа в методах доступа

Использование модификаторов доступа для свойств или индексаторов подчиняется следующим условиям:

Access Modifiers on Overriding Accessors

When you override a property or indexer, the overridden accessors must be accessible to the overriding code. Also, the accessibility level of both the property/indexer, and that of the accessors must match the corresponding overridden property/indexer and the accessors. For example:

public class Parent

{

public virtual int TestProperty

{

// Notice the accessor accessibility level.

protected set { }

// No access modifier is used here.

get {return 0;}

}

}

public class Kid : Parent

{

public override int TestProperty

{

// Use the same accessibility level as in the overridden accessor.

protected set { }

// Cannot use access modifier here.

get {return 0;}

}

}