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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:07:12+00:00 2026-06-11T14:07:12+00:00

System.ValueType is a class , yet all value types are structs. If I create

  • 0

System.ValueType is a class,
yet all value types are structs.

If I create an instance of ValueType like so:

System.ValueType foo = 5;

…is it saved on the heap or on the stack?

  • 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-11T14:07:13+00:00Added an answer on June 11, 2026 at 2:07 pm

    System.ValueType is not a value-type. Value-types are things that inherit from ValueType, but not ValueType itself. So:

    System.ValueType foo = 5; 
    

    here, 5 is loaded on the stack. This is then boxed (with a box of type int) onto the heap. The object reference is then assigned to the reference foo. We can see this by looking at the IL for that:

    ldc.i4.5 // push int32 value 5 onto the stack
    box int32 // box the value at the top of the stack, type int32
    stloc.0 // assign to "foo"
    

    In general, though: structs can be either on the heap or on the stack, depending on the context. Frankly, it doesn’t matter which – because both are implementation details. It is the behaviour that matters… and (at least in their unboxed form), the key point about structs is their copy-on-assign semantic.

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

Sidebar

Related Questions

I want to write a 'Date' class that behaves like a Value Type. for
public static class Extensions { public static T Include<T>(this System.Enum type,T value) where T:struct
It is true in .NET that all types inherit from System.Object. What I find
The system I'm working on uses a large number of custom value types internally.
IF i have the following: MyString.ValueType = typeof(System.Decimal); how can i make this have
I read that System.Drawing.Point is a value type. I do not understand. Why?
Why can't I use a constraint of where T : System.ValueType ? Why does
I have an hierarchical structure of classes like this public class Class1 { internal
Quoting from the MSDN Link for ValueType Class In cases where it is necessary
MSDN defines System.Enum as an abstract class: [SerializableAttribute] [ComVisibleAttribute(true)] public abstract class Enum :

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.