C#中的OO问题

Joh*_*ack 2 c# oop

class Frame
{
    static int X;
    static int Y;
    static uint Color;

    static protected bool Check()
    {
        return (Coords.GetPixelColor(X, Y) == Color);
    }
}

class frameBeginning : Frame
{
    static int X = 1;
    static int Y = 2;
    static int Color = 3;
}
Run Code Online (Sandbox Code Playgroud)

frameBeginning.Check();无法编译,因为Check()其保护级别无法访问.

但为什么,Check()受到保护?

Szy*_*zga 8

这不是问题.您看到的行为是受保护定义的一部分.如果要从frameBeginning或frame类的代码外部调用frameBeginning.Check,则该方法需要是publicinternal.