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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:24:10+00:00 2026-05-18T04:24:10+00:00

Considering this class: public class Foo { public Int32 MyField; } I guess the

  • 0

Considering this class:

public class Foo
{
    public Int32 MyField;
}

I guess the “MyField” member is not on the thread stack because as it could be accessed by several threads, it has to be definitely in the managed heap, but does it means it is boxed and unboxed everytime it is used?

Thanks in advance

  • 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-18T04:24:10+00:00Added an answer on May 18, 2026 at 4:24 am

    No, it is not boxed every time it is used. Boxing only occurs when you are coercing a value type into a reference type – it really has nothing to do with where the actual memory for the value was allocated (or even if any memory was allocated).

    In your case, it’s how you act on MyField that will determine if it’s boxed, not how Foo is treated.

      //No Boxing
      var f = new Foo();
      f.MyField = 5;
      int val = f.MyField;
    
    
      //Boxing
      var f = new Foo();
      f.MyFIeld = 5;
      object val = f.MyField;
    

    Note that in the second example val now contains a reference to a boxed int. MyField is still (and will always remain) an unboxed int and can be accessed without unboxing (thanks for pointing out the needed clarification, LukeH)

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

Sidebar

Related Questions

Considering this class public class XQueries { public IQueryable Query1() { using (XEntities context
I'm not considering this - I'm comfortable with C# and VB, but an expert
Considering such code: class ToBeTested { public: void doForEach() { for (vector<Contained>::iterator it =
Considering this code, can I be absolutely sure that the finally block always executes,
I have this small code library that I'm considering releasing into Open Source. I
Like many others on this site I am considering a move to ASP.NET MVC
I'm sure this is a subject that's on most python developers' minds considering that
Our company is considering upgrading our SQL server. At this point, would it be
I remember seeing a debate about this somewhere, and am currently considering removing a
Considering private is the default access modifier for class Members, why is the keyword

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.