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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:44:59+00:00 2026-05-16T20:44:59+00:00

There is probably a quite logical explanation to this, but I have a question.

  • 0

There is probably a quite logical explanation to this, but I have a question.

Let’s say I have a variable of type Rectangle called _rect. I can now say _rect.X = 50; without any problems.

Now I have a class with a property called Rect that exposes the internal variable _rect.

Then, if I try to write Rect.X = 50; I get the following compilation error:

Cannot modify the return value of ‘TestClass.Rect’ because it is not a variable.

I can write Rect = new Rectangle( 50, Rect.Y, Rect.Width, Rect.Height) like for a immutable type, but for non-immutable types, are there any other way of doing this?

I want to use auto-properties for this rectangle field, but it’s really annoying not being able to modify it inside the class itself.

Are there any way short of making a backing field and dropping the auto-property?

  • 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-16T20:44:59+00:00Added an answer on May 16, 2026 at 8:44 pm

    The reason for this error is because Rectangle is a value type (struct) in contrast to reference types (classes). You cannot modify the X property because when you use the Rect property getter a new value for the rectangle is returned (the getter is a function). If it was a reference type you are manipulating the pointer and this would be possible.

    This is an important aspect of value vs reference types to be aware of.

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

Sidebar

Related Questions

First of all there is probably a question like this already but i couldn't
This question is probably quite dumb, but I can't find an example and can't
This is probably quite a straightforward question, but I can't find an answer elsewhere
This is probably a very obvious question but I can't quite figure it out.
This is probably quite a newb question, but I can't seem to figure it
This is probably quite trivial but.... I have a quite complicated linq query that
I'm quite new to Java, so there is probably a simple explanation to this
There is probably already an answer for this somewhere, but I must not be
There is probably a simple answer for this, but I couldn't find one, so
I'm new to the OOP paradigm, so there's probably a simple explanation for this

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.