【发布时间】:2022-11-23 03:00:07
【问题描述】:
为什么“internal const”可以在子类中被覆盖而“protected const”不能?
示例代码:
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";
}
期望 B.pStr 返回“childP”。
【问题讨论】:
标签: c# .net constants protected internals