Friday 18 August 2017

Use of Private constructor in c#



Private constructor is generally used in the scenario where you do not want your user to create the instance of the class. The ideal example would be when you design a class based on Singleton pattern. 

Private constructors are used to prevent creating instances of a class when there are no instance fields or methods, or when a method is called to obtain an instance of a class.

Generally, they are used in 
singleton design patterns, where the code ensures that only one instance of a class can ever be created.

No comments:

Post a Comment