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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:47:06+00:00 2026-05-11T16:47:06+00:00

Possible Duplicate: When do you use the “this” keyword? Hello, I understand that the

  • 0

Possible Duplicate:
When do you use the “this” keyword?

Hello,
I understand that the This keyword is used to refer to an instance of the class, however, suppose I have a class called Life, which defines two fields, the person (their name) and their partner(their name):

class Life
{
    //Fields
    private string _person;
    private string _partner;

    //Properties
    public string Person
    {
        get { return _person; }
        set { _person = value; }
    }

    public string Partner
    {
        get { return _partner; }
        set { _partner = value; }
    }

    //Constructor 1
    public Life()
    {
        _person = "Dave";
        _partner = "Sarah";

        MessageBox.Show("Life Constructor Called");
    }

    //Constructor 2
    public Life()
    {
        this._person = "Dave";
        this._partner = "Sarah";

        MessageBox.Show("Life Constructor Called");
    }
}

Is there a difference between constructor 1 and constructor 2!?
Or is it just better coding practice to use the “This” keyword?

Regards

  • 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-11T16:47:06+00:00Added an answer on May 11, 2026 at 4:47 pm

    The constructors are the same. The reason I would prefer the second is that it will allow you to remove the underscores from your private variable names and retain the context (improving understandability). I make it a practice to always use this when referring to instance variables and properties.

    I no longer use the this keyword in this way after moving to a different company with different standards. I’ve gotten used to it and now rarely use it at all when referring to instance members. I do still recommend using properties (obviously).

    My version of your class:

    class Life
    {
        //Fields
        private string person;
        private string partner;
    
        //Properties
        public string Person
        {
            get { return this.person; }
            set { this.person = value; }
        }
    
        public string Partner
        {
            get { return this.partner; }
            set { this.partner = value; }
        }
    
    
        public Life()
        {
            this.person = "Dave";
            this.partner = "Sarah";
    
            MessageBox.Show("Life Constructor Called");
        }
    }
    

    or, even better, but not as clear about the use of this with fields.

    class Life
    {
    
        //Properties
        public string Person { get; set; }
        public string Partner { get; set; }
    
        public Life()
        {
            this.Person = "Dave";
            this.Partner = "Sarah";
    
            MessageBox.Show("Life Constructor Called");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: When do you use the “this” keyword? If I have the following
Possible Duplicate: When do you use the “this” keyword? I'm writing some of my
Possible Duplicate: When to use “strictfp” keyword in java? What is the use of
Possible Duplicate: Is it OK to use “delete this” to delete the current object?
Possible Duplicate: In jquery: Use attr(“class”) value as a selector? I have fields with
Possible Duplicate: Failed to connect to mailserver at “localhost” port 25 I used this
Possible Duplicate: Is there a “Set” data structure in .Net? Duplicate: this is a
Possible Duplicate: Allen Holub wrote “You should never use get/set functions”, is he correct?
Possible Duplicate: How do I assign by “reference” to a class field in c#?
Possible Duplicate: ASP.NET “special” tags I hope this isn't too much of a newbie

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.