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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:45:35+00:00 2026-06-06T02:45:35+00:00

I will first illustrate my issue with some code: class ExampleClass { private Vector2

  • 0

I will first illustrate my issue with some code:

class ExampleClass
{
    private Vector2 _myVector;

    public Vector2 MyVectorProperty { get { return _myVector; } set { _myVector = value; } }

    private void MyMethod()
    {
        _myVector = Vector2.Zero; // Setting to zero

        MyVectorProperty.X = 5; //Cannot modify the expression because it is not a variable (returns an error)

        _myVector.X = 5; //Works fine!
    }
}

As you can see, I am getting the error “Cannot modify the expression because it is not a variable” when trying to change the value of X and Y on the vector using the property. I am unsure why this happens and haven’t had any luck looking on the net and i was wondering why this is and how (if) I can fix it?

Another sub question, is it good programming practice to use the public properties or the private/protected fields when working inside the class they belong to?

  • 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-06T02:45:37+00:00Added an answer on June 6, 2026 at 2:45 am

    You should be happy compiler does not let you do so, otherwise you’ll be really surprised with result of operation being lost.

    • MyVectorProperty is property – which means getting the value is call to a function returning the value (something like this.get_MyVectorProperty()).
    • Since type of the MyVectorProperty is Vector2 which is struct it means that value returned by the get_... function is a copy of value, not reference like it would be in case of normal class.
    • Changing field X of above copy would simply change X inside of copy of the value, and since that copy of the value is not assigned to anything it will be lost.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit This code should illustrate the whole problem: [XmlInclude(typeof(AThing1))] public abstract class AThing {
The following code is just used to illustrate my question. template<class T> class array<T>
I am sorry if my question is not overly clear. I will first illustrate
A question that I have never solved. I will illustrate with two code samples
The problem I have when the following code executes, it will first display the
I know one awkward solution for this taks will be : first use ct
First I will try to explain what I want to do. The app loads
First I will explain what I am trying to do. I am trying to
This will be my first iOS app with any bit of complexity. I'd like
I need a regular expression that will match the first letter of a song

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.