Click here to Skip to main content
13,191,400 members (75,952 online)
Rate this:
Please Sign up or sign in to vote.
See more:
can we have two overloaded private constructors in a class?
Posted 10-Dec-12 0:06am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Yes you can.

 namespace Private_Classes
    class Program
        static void Main(string[] args)
        private class Test
            public Test()
            public Test(string Value)
            //these  throws an compile Error "already defines a member called 'Test' with the same parameter types"
            //public Test(string TurnOff)
            //public Test()

But as this forum thread indicates where you would more than likely use an approach.

Private class in C#[^]
Comments 10-Dec-12 7:00am
Simon, the question is about private constructors. do u remember?
Simon_Whale 10-Dec-12 7:04am
then how would you make a usable private class with 2 private constructors? I'm curious that is why I am asking. As you can't see more than the first default constructor if you attempt to construct the example I've given. 10-Dec-12 7:06am
please check this link:


hope it helps.
Simon_Whale 10-Dec-12 7:15am
So to truly answer the OP question the answer should of been NO. As from both the examples that you have shown only allow for a single private constructor as this is used to initalise variables or perform some logic, and I also tried to achieve what he was after in a sample application and couldn't with multiple PRIVATE constructors.

To allow near to his answer the Constructors should be public and the class declaration private.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171017.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100