How to call protected constructor in c#?

后端 未结 8 1856
不知归路
不知归路 2021-02-19 00:51

How to call protected constructor?

public class Foo{
  public Foo(a lot of arguments){}
  protected Foo(){}
}
var foo=???

This obviously fails

8条回答
  •  迷失自我
    2021-02-19 01:04

    The only way to cause a protected constructor to be called is to derive from the class and have the derived class delegate to it or to have a static method create it or some other internal method.

    EDIT: What the Skeet said!

提交回复
热议问题