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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:58:25+00:00 2026-05-27T06:58:25+00:00

I have declared a private field and a public property for a given class.

  • 0

I have declared a private field and a public property for a given class.

From other units I can access the field through the public property that provides access to it.

But inside the same unit where this class is declared I have the choice to access the field directly or through the property.

What is the suggested best practice: direct read/write to the field or through the property that provides read and write access to it?

  • 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-27T06:58:26+00:00Added an answer on May 27, 2026 at 6:58 am

    Contrary to David’s taste, I always use the private/protected field, but only within the same class (when private) or within a derivative (when protected). Strangly enough, the reason is readability for me too:

    • By now, FCount reads as Count,
    • Using the private field makes it clear I am working on internals,
    • And in the sporadic situation where I use the property, then it is obvious that I need to trigger the setter or getter behind it.

    The key point here is being consistent. Choose one, and stick to it. There is no right nor wrong.

    Update due to Jerry’s comment:

    My point about being consistent is a general advise for everyone’s own benefit. Accustom yourself with one default syntax, and your code will be crystal clear (to you I mean) for the rest of your life.

    Of course, when you choose using private fields, there will be incidental situations you must use the property instead. But this applies vice versa: if you choose to use the property, then there will be situations you have to use the private field. I am only saying that when you stick to a system, the exceptions will more clearly look like exceptions.

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

Sidebar

Related Questions

If I have a java class which is package-private (declared with class, not public
I have a class that exposes an auto implemented property Enabled Public MustInherit Class
I have declared a class as class DCFrameListener : public FrameListener, public OIS::MouseListener, public
I have a custom class declared as follows (in vb.net) <Serializable()> Public Class NumInfo
I have an interface that has ~16 input field boxes. They are all declared
In my mvvm ViewModel I have such field public int Delta { get; private
I have learned that in a class you can declare variables and methods. They
I have a NumericStepper declared as a UIComponent: <![CDATA[ private var component:UIComponent; component =
I have a variable that indicates the length of time the UI can be
I have a business application (created from template) and I can change language dynamically

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.