473,385 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Edit structure members when a property

Hi, I was wondering why I couldn't assign values to a rectangles member when
the rectangle is a property of a class ie.

// This works ok as expected.
Rectangle r = new Rectangle(10, 10, 10, 10);
r.Y = 20;

// when a rectangle is a property of my own class, I can't assign directly
to the Y value.
MyClass c = new MyClass();
c.MyRectangle = new Rectangle(10, 10, 10, 10);
c.MyRectangle.Y = 20; // Error: Cannot modify the return value because it is
not a variable!!!!!!!!!

c.MyRectangle = new Rectangle(10, 20, 10, 10); // ok
Thanks in advance.
Steve.
Aug 22 '06 #1
1 953
Steve <st**********@lineone.netwrote:
Hi, I was wondering why I couldn't assign values to a rectangles member when
the rectangle is a property of a class ie.

// This works ok as expected.
Rectangle r = new Rectangle(10, 10, 10, 10);
r.Y = 20;

// when a rectangle is a property of my own class, I can't assign directly
to the Y value.
MyClass c = new MyClass();
c.MyRectangle = new Rectangle(10, 10, 10, 10);
c.MyRectangle.Y = 20; // Error: Cannot modify the return value because it is
not a variable!!!!!!!!!

c.MyRectangle = new Rectangle(10, 20, 10, 10); // ok
The c.MyRectangle part would return the current rectangle, which is a
*value* type value. Changing the value of Y would make no difference
whatsoever to the value underlying the c.MyRectangle property.

I don't have time to explain further, but basically you need to look
into the differences between reference types and value types.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andre | last post by:
I have two questions; 1) When executing the sub routine "TestStructure", I'm trying to update the member "intTyres" in the structure "structureCar" dynamically using System.Reflection. The code...
5
by: brett valjalo | last post by:
Hey Gang! SORRY ABOUT THE LENGTH! Nice to see some of the same faces around this place from way back when ... Whatta buncha CDMA addicts some o' y'all are ;) Don't get me wrong, I...
13
by: John | last post by:
In the course of an assignment, I learned the hard way that I shouldn't try to free a malloc'd member of a malloc'd structure after having freed that structure (i.e., free( structure ); free(...
15
by: damian birchler | last post by:
Hi I'm wondering of what type a structure is. Of course, it is a _structure_, but an array isn't an _array_ either. So of what type is a structure? I'd say a pointer, am I right?
6
by: STom | last post by:
I have a class declare like this: <Serializable>Public Class Talk Public Structure _localTalk Public _iTalkNumber as Integer End structure End Class I can see the structure from other...
3
by: snesbit | last post by:
I have a structure called SearchAreaListItem. The structure has some properties. The application implements this as a collection.generic.list(of SearchAreaListItem) I load the collection up ...
2
by: Steve Barnett | last post by:
I have a field in a user control which is a structure. The structure has three fields, an integer a string and a Boolean. When I put my user control on a form, the property that references the...
4
by: John | last post by:
I am having a problem accessing the members in a structure via an interface and Class. ***Development Code*** Structure Person Public Name as String End Structure Interface IData Public...
4
by: shapper | last post by:
Hello, I have a class which I am using in my profile. I made this class Serializable by using: <Serializable()_ Public Class Options One of the properties in this class is of type Level...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.