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 1089851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:17:18+00:00 2026-05-16T23:17:18+00:00

Under what conditions am I supposed to make the :base() and :this() constructor calls

  • 0

Under what conditions am I supposed to make the :base() and :this() constructor calls following my constructor’s parentheses (or even in other places in the code). When are these calls good practices and when are they mandatory?

  • 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-05-16T23:17:19+00:00Added an answer on May 16, 2026 at 11:17 pm

    : base(...)

    If you omit the call to a base constructor it will call the default base constructor automatically.

    It is mandatory to call a base constructor explicitly if there is no default constructor.

    Even if there is a default constructor you may still wish to call a different constructor than the default constructor. In this case you may still wish to use base(foo, bar) to call a different constructor than the base constructor.

    I do not consider it to be a bad practice to omit base() when you want to call to the base class default constructor, although if you like to be explicit I see no harm in including it. It is a matter of taste.

    : this(...)

    This syntax allows you to call one constructor with a different signature from another within the same class. It is never mandatory to do this, but can sometimes be useful.

    An example of when it can be useful is for reusing common code in the constructors. For example in C# 3.5 or before you may want to simulate optional parameters on a constructor:

    Foo(int x, int y)
    {
         this.x = x;
         this.y = y;
    }
    
    Foo(int x) : this(x, 10) {}  // y defaults to 10
    

    With C# 4.0 optional parameters are now available which reduces the need for this approach.

    An alternative way to reuse code in constructors is to factor it out into a static function which is called from each constructor that wishes to use it.

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

Sidebar

Related Questions

I have hack I need to employ under these conditions: It's the last page
I wrote this quickly under interview conditions, I wanted to post it to the
Under what conditions can I put PHP into Javascript code? Is it always ok?
I need to investigate/test the behavior of some code on Linux under conditions where
I've written some code that I think should be failing under certain conditions, but
I want to check whether records exist under conditions. This line works fine: DataContext.Alerts.Count(e
Under some conditions, I want to make a celery task fail from within that
How can I hide a menu item under certain conditions in MFC? I'm not
I have a control that goes inactive under some conditions in my iPhone app.
I'd like to write a script that (under certain conditions) will execute gdb and

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.