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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 127k
  • Answers 127k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I assume you're using http://www.eggheadcafe.com/community/aspnet/17/10084853/xml-viewer.aspx as your sample data... As… May 12, 2026 at 5:35 am
  • Editorial Team
    Editorial Team added an answer Wjy don't you have a pointer to your UITableView? Assuming… May 12, 2026 at 5:35 am
  • Editorial Team
    Editorial Team added an answer caf's answer seems to be right. What I actually expected… May 12, 2026 at 5:35 am

Related Questions

Possible Duplicate: Allen Holub wrote “You should never use get/set functions”, is he correct?
Possible Duplicate: When do you use Java’s @Override annotation and why? From the javadoc
Possible Duplicate: When do you use Java’s @Override annotation and why? Is there any
Possible Duplicate: How do you remove Subversion control for a folder? I am implementing

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.