摘要:通常一个类的constructor是protected的时候,是不希望用户直接调用它.但是我发现可以用这么一个方法来实现调用:
public class ClassA
{
protected ClassA()
{
}
}
class ClassX : ClassA
{
static public ClassA CreateClassA()
{
return new ClassA();
}
}
关于protected成员的调用,以前有类似的blog的.关于protected的Quiz protected的成员是不能变相被子类调用的,例如
class ControlUtility : System.Web.UI.Control
{
public System.Web.HttpContext GetContext(System.Web.UI.Control ctrl)
{
return ctrl.Context;
}
}是不能编译通过的,但constructor却能通过当然,如果该类是sealed就不行了,那么protected和private也没有区别了....[
阅读全文]