Can we have a private constructor inside a public class in C#?

In one of my interviews, I was asked this question:

Can we have a private constructor inside a public class in C#?

At that moment, I said no, but the correct answer is yes. We can have a private constructor inside a public class. The true question here is why and when do we need a private constructor in a public class?

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *