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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:58:56+00:00 2026-06-17T18:58:56+00:00

Possible Duplicate: Should you access a variable within the same class via a Property?

  • 0

Possible Duplicate:
Should you access a variable within the same class via a Property?

I ran into this recently and was curious if there was some sort of standard for which one you should reference while inside a class.

I mean really it shouldn’t make a difference whether you access the member variable directly or go through the property (unless you need to dodge some custom setter code), but I wanted to be sure there wasn’t a best practice for it.

partial class MyClass {
    private string foo;

    internal string Foo {
        get {
            return foo;
        }

        private set {
            foo=value;
            // I do other stuff
        }
    }

    public void DoSomething() {
        //Option 1;
        Foo="some string";

        //Option 2;
        foo="some string";
    }
}
  • 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-17T18:58:57+00:00Added an answer on June 17, 2026 at 6:58 pm

    This shouldn’t be a choice you really make. Either the code in the setter is supposed to run, in which case use the property, or it’s not, in which case you use the member variable. In most all situations one is right and one is wrong. Neither is always right/wrong in the general case, and it’s unusual for it to “not matter”.

    For example, if the setter code is firing a “changed” event, do you want external objects to be notified that it changed, or not? If you’re changing it in response to a previous change, probably not (infinite recursion anyone?) if no, you probably want to make sure it’s fired (so that you’re not changing a value and not notifying anyone of changes).

    If it’s just validating that the value being set is valid, then either you know that, in this context, the value is already validated and must be valid, in which case there is no need to validate again; set the property. If you haven’t yet validated what you’re about to set then you want the validation logic to run, so use the property.

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

Sidebar

Related Questions

Possible Duplicate: Property Name and need its value Hi, This one should be easy
Possible Duplicate: Within the Containing Class, Use Property or Field? Take a look at
Possible Duplicate: Why should I use templating system in PHP? I was just curious
Possible Duplicate: Why should the interface for a Java class be prefered? When should
Possible Duplicate: What are access specifiers? Should I inherit with private, protected or public?
Possible Duplicate: Why shall I use the “using” keyword to access my base class
Possible Duplicate: What are access specifiers? Should I inherit with private, protected or public?
Possible Duplicate: Difference between Property and Field in C# .NET 3.5+ Why should I
Possible Duplicate: When should I use a List vs a LinkedList This question is
Possible Duplicate: Access a view helper for a model in rails I know this

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.