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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:37:52+00:00 2026-05-23T03:37:52+00:00

This question is more out of curiosity than a real problem. Consider the following

  • 0

This question is more out of curiosity than a real problem. Consider the following code (C# 4.0, if it matters):

class Program {
  static Point myPoint = new Point(3, 5);

  static void Main(string[] args) {
    Console.WriteLine("Point Struct Before: " + myPoint);
    object point = GetPoint();
    Console.WriteLine("Point Object Before: " + point);
    myPoint.X = 10;
    Console.WriteLine("Point Struct After: " + myPoint);
    Console.WriteLine("Point Object After: " + point);
  }

  static object GetPoint() {
    return myPoint;
  }
}

This outputs the following:

Point Struct Before: 3;5
Point Object Before: 3;5
Point Struct After: 10;5
Point Object After: 3;5

Now, this works as it should, meaning the point returned by GetPoint() is being copied rather than referenced. (Otherwise the last line would also have read “10;5”.)

My question now is: Why does this work? How does the compiler know whether to copy or reference an object? Does this mean that this decision is done during runtime rather than during compilation?

Also, this now allows me to set point to null whereas structs can’t be set to null. Is the struct automatically converted into a nullable type?

  • 1 1 Answer
  • 3 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-23T03:37:53+00:00Added an answer on May 23, 2026 at 3:37 am

    You are observing the process called boxing. It essentially converts a value type into a reference type.

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

Sidebar

Related Questions

This is a code review question more then anything. I have the following problem:
This is a question more out of curiosity rather than being stuck. I know
This question is more out of curiosity than purpose. Can we change the output
This question is more about guidance than actually solving my problem: I need to
This question is more a re-insurance than one directly about how to code. As
This is a bit of a random question that is more out of curiosity
This is more out of curiosity than anything else, as I'm failing to find
Hey guys, this is more of a question out of curiosity, but is it
I had a question about C++ destructor behavior, more out of curiosity than anything
Arbitrary PHP question, more/less out of curiosity. I apologize if this is a silly

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.