为什么“内部常量”在子类中被覆盖,而“受保护常量”却不能?
示例代码:
class A
{
internal const string iStr = "baseI";
protected const string pStr = "baseP";
void foo()
{
string s = B.iStr; //childI
string t = B.pStr; //baseP
}
}
class B : A
{
internal new const string iStr = "childI";
protected new const string pStr = "childP";
}
Run Code Online (Sandbox Code Playgroud)
预期 B.pStr 返回“childP”。