Hello, i would like to know how to instantiate an object using private constructor? and what are the main benefits to use private constructor?
namespace Practice
{
public class Test
{
int a;
public Test()
{
}
private Test(int a)
{
this.a = a;
}
}
public class Test2
{
void method()
{
Test obj1 = new Test();
}
}
}

VulpesPosted Jan 20, 2015, 8:04 AM
The output is :
The value of 'a' is 42
Bhushan GawalePosted Jan 20, 2015, 6:49 AM
http://msdn.microsoft.com/en-us/library/kcfb85a6.aspx