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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:51:08+00:00 2026-06-11T00:51:08+00:00

value type variables contain the actual data directly and reference type variables contain the

  • 0

value type variables contain the actual data directly and reference type variables contain the reference to the actual data.

I think of this as:

l.h.s is value type and r.h.s is reference type

enter image description here

on the left hand side, if I copy i into j, a new memory location is filled with same original data (45).

on the right hand side, if I copy k to l, a new memory location is filled with the reference to the object; and this reference points to the actual object in memory.

now, I am confused about this reference type copying. here’s a slight different thing:

enter image description here

Here, the copy on the r.h.s makes l points to same location as k.

My question is 1. “Which one is truer?” or is there more to it than I imagined?

Also, value types may be allocated on heap, depending upon the how jitter sees it fit, then 2. Can we force a reference type to be allocated on stack?

Sorry for sloppy image editing.

  • 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-11T00:51:10+00:00Added an answer on June 11, 2026 at 12:51 am

    The first picture is better, l and k are different variables, occupying different places in memory.

    value types may be allocated on heap, depending upon the how jitter sees it fit

    Actually it depends more on the context and the way a value is used. A value-type field would always be allocated on the heap, boxing and closures are other reasons.

    However, the 2nd picture applies when l is a ref parameter:

    MyClass k = new ...;
    M(ref k);
    
    void M(ref MyClass l) { /* Here l is an alias for k */ }
    

    then 2. Can we force a reference type to be allocated on stack?

    There is something like stackalloc but it’s an optimization that is ‘invisible’ to a C# programmer.
    The simple and most useful answer is: No.

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

Sidebar

Related Questions

Is string a value type or a reference type? I just can't find a
When a value type is boxed, it is placed inside an untyped reference object.
I know the general difference between value type and reference type, and I also
I've some scenarios where i need to pass value type as reference without changed
Does anyone know how to convert the string value type -4,5 or 5,4 into
I have string value and Type of some variable (For example int and 32
can we assign null value to struct type of variable? struct MyStruct { }
want to know why String behaves like value type while using ==. String s1
.NET I want to clone a value type's fields. How can i set a
Is it possible to cast a custom class to a value type? Here's an

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.