Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8112927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:39:58+00:00 2026-06-06T02:39:58+00:00

I have a class with two constructors (C#). Here is the code snippet: public

  • 0

I have a class with two constructors (C#). Here is the code snippet:

public class FooBar()
{
    public FooBar(string s)
    {
        // constructor 1, some functionality
    }

    public FooBar(int i) : this("My String")
    {
        // constructor 2, some other functionality
    }

}

Yes, I know that I can call one constructor from another using the above mentioned approach. But in this scenario, if I call constructor 2, all statements in constructor 1 will run BEFORE the very statement in constructor 2 is executed.

What I want is that after all statements in constructor 2 are run, then it will call constructor 1.

In my exact situation, I am doing user authentication. Constructor 1 retrieves user information with just the user ID, but constructor 2 does the user authentication using email and password. If a user is in the database, it gets the user ID and now I want constructor 1 to populate all properties of the class.

Please let me know if you require additional information. If you think that there is another better approach, I would be happy to listen the suggestion.

UPDATE 1:
I wonder why something like this is not implemented:

public FooBar(bool b)
{
    // constructor 3, some more functionality
    this.FooBar("My String"); // calling constructor 1
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:39:59+00:00Added an answer on June 6, 2026 at 2:39 am

    In this case just do not use constructor calls, but something like :

    public class FooBar()
    {
        public FooBar(string s)
        {
            Init1();
        }
    
        public FooBar(int i)
        {
            Init2(); 
            Init1();
        }
    
    }
    

    Where I supposed that Init1(..) and Init2(..) are methods related to some specific intialization logic of corresponding constructor.

    Actually you can arrange this function calls in a way that better fits your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class with two constructors that look like this: public MyClass(SomeOtherClass source)
We have some code that looks like this: class Serializer { public: template<class Type>
Given I have a class with two constructors: public class TestClass { ObjectOne o1;
I have two constructors which feed values to readonly fields. public class Sample {
Let's say I have two constructors in my class: public User (List<Source1> source){ ...
I have a class with two constructors, one that takes no arguments and one
I have a base class, B, which has two constructors, one with no paremeters
I have a main class and two extended classes: class Main { public $foo;
Say I have a multiple inheritance scenario: class A(object): # code for A here
suppose I have the following class: class MyInteger { private: int n_; public: MyInteger(int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.