namespace PalleTech
{
public class Parent
{
private int test = 123;
public virtual int TestProperty
{
// Notice the accessor accessibility level.
set {
test = value;
}
// No access modifier is used here.
protected get { return test; }
}
}
public class Kid : Parent
{
private int test1 = 123;
public override int TestProperty
{
// Use the same accessibility level as in the overridden accessor.
set { test1 = value / 123; }
// Cannot use access modifier here.
protected get { return 0; }
}
}
public class Demo:Kid
{
public static void Main()
{
Kid k = new Kid();
Console.Write(k.TestProperty);
}
}
}
错误 1 无法通过“PalleTech.Kid”类型的限定符访问受保护的成员“PalleTech.Parent.TestProperty”;限定符必须是“PalleTech.Demo”类型(或派生自它)