【发布时间】:2014-05-21 06:49:36
【问题描述】:
using System.IO;
using System;
using Assembly2;
// DLL 1
namespace Assembly1
{
class class1 : class2
{
static void Main()
{
Console.WriteLine(new class2().sample); //Cannot access. Protected means --> accessible to the derived classes right ? (But, note that this is a different assembly. Does not work because of that ?)
}
}
}
// DLL 2
namespace Assembly2
{
public class class2
{
protected string sample = "Test";
}
}
在上面的简单代码中,
我无法访问程序集 2 中的字符串 sample,尽管我派生自 class2
From MSDN: The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
这个定义是只代表同一个程序集还是可以跨程序集访问受保护的成员?
【问题讨论】:
标签: c# .net protected access-modifiers