Hi
we facing a problem that how we can put a private constructor in a public class if not than give reason.
thanks.....
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted Mar 28, 2012, 11:43 PM
C# allows you to make the constructor as private in the public class.
public class Sample
{
private Sample() //Its valid
{
}
}
If you are trying to create the instance of the class Sample
Sample sample = new Sample(); //It throws error.
But if you have static properties then you are eligible to access those properties. Because it can be accessed without creating the instanced.
For more info,
http://msdn.microsoft.com/en-us/library/kcfb85a6(v=vs.80).aspx
Sam HobbsPosted Mar 28, 2012, 10:54 PM