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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:05:19+00:00 2026-05-29T16:05:19+00:00

I’ve recently tried to create a property for a Vector2 field, just to realize

  • 0

I’ve recently tried to create a property for a Vector2 field, just to realize that it doesn’t work as intended.

public Vector2 Position { get; set; }

this prevents me from changing the values of its members (X & Y)

Looking up information on this, I read that creating a property to a Vector2 struct returns only a copy of the original object and not a reference.

As a Java developer this confuses me.

When are objects in C# passed by value and when are they passed by reference?
Are all struct objects passed by value?

  • 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-29T16:05:20+00:00Added an answer on May 29, 2026 at 4:05 pm

    It is important to realise that everything in C# is passed by value, unless you specify ref or out in the signature.

    What makes value types (and hence structs) different from reference types is that a value type is accessed directly, while a reference type is accessed via its reference. If you pass a reference type into a method, its reference, not the value itself, is passed by value.

    To illustrate, imagine we have a class PointClass and a struct PointStruct, defined analogously (omitting irrelevant details):

    struct PointStruct { public int x, y; }
    
    class PointClass { public int x, y; }
    

    And we have a method SomeMethod that takes these two types by value:

    static void ExampleMethod(PointClass apc, PointStruct aps) { … }
    

    If we now create two objects and call the method:

    var pc = new PointClass(1, 1);
    var ps = new PointStruct(1, 1);
    
    ExampleMethod(pc, ps);
    

    … we can visualise this with the following diagram:

    diagram

    Since pc is a reference, it doesn’t contain the value in itself; rather, it references an (unnamed) value somewhere else in memory. This is visualised by the dashed border and the arrow.

    But: for both pc and ps, the actual variable is copied when calling the method.

    What happens if ExampleMethod reassigns the argument variables internally? Let’s check:

    static void ExampleMethod(PointClass apc, PointStruct aps); {
        apc = new PointClass(2, 2);
        aps = new PointStruct(2, 2);
    }
    

    Output of pc and ps after calling the method:

    pc: {x: 1, y: 1}
    ps: {x: 1, y: 1}
    

    → ExampleMethod changed a copy of the values, and the original values are unaffected.

    This, fundamentally, is what “pass by value” means.

    There’s still a difference between reference and value types, and that comes into play when modifying members of the value, not the variable itself. This is the part that trips people up when they are confronted with the fact that reference types are passed by value. Consider a different ExampleMethod.

    static void ExampleMethod(PointClass apc, PointStruct aps) {
        apc.x = 2;
        aps.x = 2;
    }
    

    Now we observe the following result after calling the method:

    pc: {x: 2, y: 1}
    ps: {x: 1, y: 1}
    

    → The reference object was changed, whereas the value object wasn’t. The diagram above shows why that is: for the reference object, even though pc was copied, the actual value that both pc and apc reference remains identical, and we can modify that via apc. As for ps, we copied the actual value itself into aps; the original value cannot be touched by ExampleMethod.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.