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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:18:06+00:00 2026-06-16T01:18:06+00:00

Was working with some code today that I did not write and noticed that

  • 0

Was working with some code today that I did not write and noticed that in a class there was a private member m_privateMember. The coder had also included a method called GetPrivateMember() which contained only return m_privateMember. It is worth mentioning that this method is heavily used within the class itself as opposed to simply using the private field that is accessible in this scope.

Semantically I see a lot of things wrong with this. A method vs. an actual getter/setter seems sloppy and I’ve always thought that if you are within class scope it is better form to actually use the private field rather than the getter. Needless to say, I am going to clean up the code purely for the reason that it does not meet coding standards in our workplace but I was curious to know if doing so would also improve performance in any way?

Does calling a method that simply returns a private field invoke more overhead?

  • 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-16T01:18:07+00:00Added an answer on June 16, 2026 at 1:18 am

    To answer your question directly: It depends.

    A property which is just a single return private field is very likely to inlined by the compiler (when optimizations are enabled) for any calls inside that assembly. In this case, it is an identical operation to accessing the field directly.

    For calls accessing the property from outside the assembly, the JIT compiler is likely to inline the call in the same way as the static compiler, but the static compiler is not allowed to do so, as it has to respect the interface provided by the assembly. This is so that you can replace a compiled assembly with a new version which has no public changes and not require a re-compile of the application source to use the new version.

    As the property gets more complicated, the chances of being inlined by either the static compiler or JIT compiler become less and the property is invoked more like you would imagine.


    All this said, the discussion of performance is really an academic one. In almost all practical examples, the difference between invoking the property versus reading the private field is trivial. The only time it will be measurable is if you’re running on some very low-spec embedded system or doing billions of reads every second for each user of your system.

    Most computers are so fast that you should be choosing the technique which makes your code more maintainable, not the one which gives you an extra 0.0000001 second decrease in execution time.

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

Sidebar

Related Questions

Working on some code today, I found that the following would work in 5.3,
I was working with some legacy code today and noticed something strange. We have
I'm working some code that inserts csv rows into an SQLite database using Python.
I'm working on some code that reads from a socket, and it goes wrong
I am working on some code, basically I have a form. On that form
I'm working with some code that I've found online and I don't quite understand
I'm working on some code that takes a hexadecimal string input and produces the
I am working on some code that I inherited from a programmer who is
I was working on some code earlier today, when I realized, Hey! This code
I'm working on rewriting some aging web applications. There are two in particular that

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.