<分区>
我(再次)提出了一个关于 protected
与 protected internal
的问题,因为我仍然不确定并且无法掌握它们。
非常感谢任何帮助。
//动态链接库 1
namespace Assembly1
{
class class1 : class2
{
static void Main()
{
new class1().Test();
}
private void Test()
{
Console.WriteLine(this.sample);
}
}
}
//动态链接库 2
namespace Assembly2
{
public class class2
{
// protected string sample = "Test";
protected internal string sample = "Test";
//Same behavior when using protected and protected internal. Why ?
}
}
两条线的行为相同。
// protected string sample = "Test";
protected internal string sample = "Test";
但我确信应该有一些区别。
MSDN says:
Protected: Access is limited to the containing class or types derived from the containing class.Protected Internal: Access is limited to the current assembly or types derived from the containing class.
只要我从基类继承,我就可以从外部程序集访问 protected
和 protected internal
。
相当困惑!两者看起来完全相似。任何人都可以通过修改上面的示例来解释我吗?