Create object instance without invoking constructor?

后端 未结 11 1949
不知归路
不知归路 2020-11-28 05:01

In C#, is there a way to instantiate an instance of a class without invoking its constructor?

Assume the class is public and is defined in a 3rd par

11条回答
  •  渐次进展
    2020-11-28 05:26

    Actually it sounds like they made the constructor internal just so you can't instantiate it. It may have a builder or factory method.

    Check out these articles:

    Preventing Third Party Derivation: Part 1

    Preventing Third Party Derivation: Part 2

    they kind of explain the reasoning.

提交回复
热议问题