Click here to Skip to main content
15,892,697 members

Response to: Question on Private Constructor

Revision 1
A private constructor can occasionally be used in .Net.
An example could be to generate a singleton class - a class which has only instance.

For e.g.

class A
{
static A o;
private void A()
{
}

public static A getinstance()
{
   if (o is null) 
   { 
      return new A();
   }
   else
   {
      return o;
   }
}
}
Posted 25-Jan-13 18:05pm by Abhinav S.
Tags: ,