473,471 Members | 4,095 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Compile error when used as Property

Hi,

Could someone please explain why the following doesn't compile. This turned
up as I was programming yesterday.

Thanks,
Zany

public class A {

public Rectangle r;

public Rectangle GetRect {

get {return r;}

}

public void Test() {

r.Width = 5; // works

Rectangle r1 = GetRect; // works

GetRect.Width = 5; // <-- won't compile

//

// Cannot modify the return value of 'A.GetRect' because it is not a
variable

//

}

}
Jan 17 '06 #1
4 998
System.Drawing.Rectangle is a struct (value type) rather than a class
(reference type).

"Zany" <za**@community.nospam> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Hi,

Could someone please explain why the following doesn't compile. This
turned up as I was programming yesterday.

Thanks,
Zany

public class A {

public Rectangle r;

public Rectangle GetRect {

get {return r;}

}

public void Test() {

r.Width = 5; // works

Rectangle r1 = GetRect; // works

GetRect.Width = 5; // <-- won't compile

//

// Cannot modify the return value of 'A.GetRect' because it is not
a variable

//

}

}

Jan 17 '06 #2
Thanks Clive

Lightbulb. Got it. Works now.

public class A {

public Rectangle r;

public Rectangle Rect {

get {return r;}

set {r = value;}

}

public void Test() {

r.Width = 5; // works (but exposed)

// or

Rectangle r1 = Rect; // works (through property)

r1.Width = 5;

Rect = r1;

}

}


"Clive Dixon" <cl*******************@digita.noluncheonmeat.com > wrote in
message news:%2****************@TK2MSFTNGP15.phx.gbl...
System.Drawing.Rectangle is a struct (value type) rather than a class
(reference type).

"Zany" <za**@community.nospam> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Hi,

Could someone please explain why the following doesn't compile. This
turned up as I was programming yesterday.

Thanks,
Zany

public class A {

public Rectangle r;

public Rectangle GetRect {

get {return r;}

}

public void Test() {

r.Width = 5; // works

Rectangle r1 = GetRect; // works

GetRect.Width = 5; // <-- won't compile

//

// Cannot modify the return value of 'A.GetRect' because it is not
a variable

//

}

}


Jan 17 '06 #3
I think the problem is the following:

GetRect.Width = 5; // <-- won't compile

needs to be changed to this:

GetRect().Width = 5; //

The class A method 'GetRect' is a function, and you used syntactically like
a variable....

In fact:

Rectangle r1 = GetRect; // works

should have also generated an error, although you say it didn't, which is
weird...

[==P==]

"Zany" <za**@community.nospam> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Hi,

Could someone please explain why the following doesn't compile. This
turned up as I was programming yesterday.

Thanks,
Zany

public class A {

public Rectangle r;

public Rectangle GetRect {

get {return r;}

}

public void Test() {

r.Width = 5; // works

Rectangle r1 = GetRect; // works

GetRect.Width = 5; // <-- won't compile

//

// Cannot modify the return value of 'A.GetRect' because it is not
a variable

//

}

}

Jan 18 '06 #4
Oh, wait. My bad. The problem is you haven't defined GetRect as a PROPERTY,
which I now see was your intent...

[==P==]

"Zany" <za**@community.nospam> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Hi,

Could someone please explain why the following doesn't compile. This
turned up as I was programming yesterday.

Thanks,
Zany

public class A {

public Rectangle r;

public Rectangle GetRect {

get {return r;}

}

public void Test() {

r.Width = 5; // works

Rectangle r1 = GetRect; // works

GetRect.Width = 5; // <-- won't compile

//

// Cannot modify the return value of 'A.GetRect' because it is not
a variable

//

}

}

Jan 18 '06 #5

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

Similar topics

1
by: Mario T. Lanza | last post by:
I am working with Visual Studio. The solution I am developing is composed of about 8 separate projects. Some of these projects represent different tiers in the N-tiered architecture (data,...
10
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
2
by: Donna Sabol | last post by:
Maybe it's not me. I posted a question earlier about not getting a function call right. Well, now I'm trying to write some very simple code, and I can't get ANYTHING to work. It won't even...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
2
by: Wayne | last post by:
The following which is driving me nuts has occurred in 2 of my databases. Both databases were written in Access 2003 and then converted back to Access 2000 format. I've done this so I can create an...
2
by: Glen | last post by:
I'm working on a custom assembly and I'm trying to figure out the best approach to handling known constraints within the assembly, once compiled, to alert the developer at compile time of a...
14
by: NRGeti | last post by:
I am learning ASP.NET using the book, "ASP.NET for Dummies". In the chapter introducing writing your own functions, I cannot get the example to run when I call it with LOCALHOST. It produces the IE...
7
by: Holger (David) Wagner | last post by:
Hi Group, I've searched the Web for precompilers that compile ASPX/ASCX pages just like it can be done with JSPs, but so far, I've only found approaches targetted at increasing the performance....
2
by: PoojaJyoti | last post by:
hi guys, I want to help for creating a GUI. I want I should get details when I click perticular name in listbox.I get entries from database to listbox but probrem arrives loading relevant details...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.