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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:29:07+00:00 2026-06-09T23:29:07+00:00

Most examples when talking about automatically generated properties talk about simple value types such

  • 0

Most examples when talking about automatically generated properties talk about “simple” value types such as strings. But what if you’d like to access a field of such a value type that is generated automatically in the IL to back up an “automatic property”?

The compiler won’t allow to do this: “Cannot modify the return value of ‘Position’ because it is not a variable”. I understand why we cannot modify this return value, but how would we then access these fields?

Say we have

class A
{
    Vector2 Position { get; set; }

    public void Foo()
    {
        Position.X = 10.0f;    // Not allowed!
    }
}

How do I access and set the field X of the Vector2 instance within class A?

  • 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-09T23:29:09+00:00Added an answer on June 9, 2026 at 11:29 pm

    Accessing reference types that are automatically generated from properties

    Your problem is that Vector2 is not a reference type; it is a value type. When you access the property Position a copy is returned, so you are attempting to mutate a temporary. In this situation you need to set a completely new value:

    Position = new Vector2(10.0, Position.Y);
    

    You could also create a private field in this case and not use an automatic property:

    class A
    {
        Vector2 _position;
        Vector2 Position 
        { 
            get { return _position; } 
            set { _position = value; }
        }
    
        public void Foo()
        {
            _position.X = 10.0f;  
        }
    }
    

    Documentation: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.vector2.aspx

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

Sidebar

Related Questions

Most of the DAO examples I've seen consist of simple queries only involving one
I'm not talking about doing a SET NOCOUNT OFF. But I have a stored
Most examples show how to redirect all subdomain traffic to a primary domain, maintaining
Most examples of creating remote branches involve pushing from a local branch Is there
In most examples that you find on the web when explicitly not using using,
I just wondered, why most Delphi examples use FillChar() to initialize records. type TFoo
Is Android 2.2 supports Carousel view? Because most of the examples I came across
There are a few examples on unobtrusive events for pure JS. Most of questions
What are the examples where we really need 3 Tier Architecture ? Can Most
I have a fairly simple query that runs super fast most of the time

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.