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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:39:33+00:00 2026-05-22T00:39:33+00:00

private double _value; public object Value { get { return _value; } } I

  • 0
private double _value;


public object Value
{
    get
   {
         return _value;
   }

}

I am doing code reviews and noticed this in our codebase. It is not a typo, but my concerns are with the boxing. That is involved when the getter is called, and given that this code is in a type, that is generated hundreds of times and the getter is called frequently I can see an issue with memory.

Are my concerns correct with memory? I mean are we doubling up due to the boxing?

  • 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-22T00:39:34+00:00Added an answer on May 22, 2026 at 12:39 am

    Yes, the code snippet that you’ve shown will indeed cause boxing. You’re forcing the run-time to convert a double into an object. If you want to prove it to yourself or a colleague, check the compiled IL for the tell-tale box and unbox instructions.

    However, while you’re correct in looking out to avoid boxing wherever possible, the actual performance penalty is not always as significant as the hype makes it out to be. Before making breaking changes to your codebase, invest some time profiling to make sure that the code you’re spending your time on is really a performance bottleneck.

    It’s not particularly clear given the specific example above why you need to return type object in the first place. Since you’re just returning the value of a private field, you could simply change the property to return type double, instead.

    Alternatively, you could convert the property to a generic method. (Properties can’t be generic, but methods can, and if you’re doing computationally-intense work inside the getter, it probably should be a method anyway.) Generics alleviate the problem of boxing, but still allow you an immense degree of flexibility in what type is returned (similar to returning type object).

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

Sidebar

Related Questions

private string? typeOfContract { get { return (string?)ViewState[typeOfContract]; } set { ViewState[typeOfContract] = value;
I would like to write this as a user defined function: private double Score(Story
which is better ??? public class Order { private double _price; private double _quantity;
private IEnumerable<string> Tables { get { yield return Foo; yield return Bar; } }
private void activateRecords(long[] stuff) { ... api.activateRecords(Arrays.asList(specIdsToActivate)); } Shouldn't this call to Arrays.asList return
I have a webservice that returns a complex value (this is a tree) public
Consider the following class written in Java: class NonNegativeDouble { private final double value;
. private void Form1_Load(object sender, EventArgs e) { List<CaclulatedData> tests = new List<CaclulatedData> {
I was doing a project for computer course on programming concepts. This project was
[EDIT] Alright, I edited this post since the code I posted back then had

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.