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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:48:55+00:00 2026-06-02T22:48:55+00:00

Is it good practice to use the private field, or the property, when writing

  • 0

Is it good practice to use the private field, or the property, when writing code in the class that contains them?

For example, if I have this field/property pair, classes outside this class must use the property. What about code inside the class? Should it use the private field, or should it also go through the property?

private string _foo;

protected string Foo
{
    get { return this._foo; }
}

private void SomeMethod()
{
  string dummyVariable = "snuh" + this._foo;  // So, this...
  string dummyVariable = "snuh" + this.Foo;  // ... or this?
}

One advantage of using the property here, is if there is any logic in the getter, it will still get executed. I’m curious to know if there is a best-practice policy to follow here.

  • 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-02T22:48:59+00:00Added an answer on June 2, 2026 at 10:48 pm

    When using Auto-Implemented properties, you don’t have a choice – you must use the property, as you don’t have any access to the generated field.

    If you property is not simple and does some extra work (validation, firing events etc…), you should call the property in order to centralize access and logic.

    If you have any other properties (meaning a simple property with no logic and a backing field) I would ask why are they not one of the above…

    With the example you have give, it makes little difference – it is more important to be consistent with how you use these and really boils down to personal aesthetics and coding style.

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

Sidebar

Related Questions

Is it good practice to have a class constructor that uses default parameters, or
It is good practice to use the main method to test a java/.net class?
I understand that it is good practice to use a using block when getting
When writing a Perl module, is it a good practice to use croak/die inside
is it a good practice to use private properties in codeigniter controllers ? for
So I've always been taught that good coding practice is to use accessor methods
My manager has asked me if it is good practice to use a property
For private class variables, which one is preferred? If you have a property like
I know that is good practice use LINQ instead of iterative loops, can I
I am learning some good code practice that's why i was going through some

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.