What is the need of private constructor in C#?

前端 未结 12 1534
鱼传尺愫
鱼传尺愫 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 21:55

    When you want to prevent the users of your class from instantiating the class directly. Some common cases are:

    • Classes containing only static methods
    • Singletons

提交回复
热议问题