.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Forum >> .NET Framework >> Post New QuestionBookmark and Share Subscribe to Forum

What is the use of private constructor in c#?

Posted By: Ramesh     Posted Date: April 22, 2010    Points:2   Category :.NET Framework

We have private constructor in .Net framework. What is the use of private constructor in C# or in oops concept?


Author: jagadish             
Posted Date: April 23, 2010     Points: 5   

Avoids creation of instance by other class.

Author: Sipra             
Posted Date: April 30, 2010     Points: 5   

Private constructor is a special instance constructor.
It is commonly used in classes that contain static members only.
If a class has one or more private constructors and no public constructors, then other classes are not allowed to create instances of this class except nested classes.
Basically used in Singleton Design Pattern.

Hope this helps.
If it is useful to you, Please Mark It as Answer .

Author: Sunil Yadav       [Moderator]      
Posted Date: May 25, 2010     Points: 5   


When you want to prevent direct instantiation of a class from outside caller use private constructor.

Author: Sunil Yadav       [Moderator]      
Posted Date: May 25, 2010     Points: 5   


Also u can use private constructors when your class contains only static members which is to be accessed will avoid the creation of the object for the class.

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend