What is the need of private constructor in C#?

前端 未结 12 1545
鱼传尺愫
鱼传尺愫 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:07

    For example if you have a class that should only be created through factory methods. Or if you have overloads of the constructor, and some of them should only be used by the other constructors. Probably other reasons as well =)

提交回复
热议问题