What is the need of private constructor in C#?

前端 未结 12 1555
鱼传尺愫
鱼传尺愫 2020-12-13 21:32

What is the need of private constructor in C#? I got it as a question for a C# test.

12条回答
  •  难免孤独
    2020-12-13 22:03

    You can use it with inheritance in a case where the arguments to the constructor for the base class are of different types to those of the child classes constructor but you still need the functionality of the base class in the child class eg. protected methods.

    Generally though this should be avoided wherever possible as this is a bad form of inheritance to be using.

提交回复
热议问题