473,394 Members | 2,020 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,394 software developers and data experts.

a.Amount += 10;

I guess this is a newbie question. I got an Account class with an Amount
property, like this:

public float Amount
{
get { return amount; }
set { amount = value; }
}

I need to add to this amount sometimes, but when I write like this

a.Amount += 10;

I get the error "The left-hand side of an assignment must be a variable,
property or indexer". Since a.Amount is a property, I don't understand the
complaint. Is this supposed to work or not?

Thanks,

Gustaf

Nov 15 '05 #1
2 1111
Gustaf Liljegren <gu**************@bredband.net> wrote:
I guess this is a newbie question. I got an Account class with an Amount
property, like this:

public float Amount
{
get { return amount; }
set { amount = value; }
}

I need to add to this amount sometimes, but when I write like this

a.Amount += 10;

I get the error "The left-hand side of an assignment must be a variable,
property or indexer". Since a.Amount is a property, I don't understand the
complaint. Is this supposed to work or not?


Have you *actually* got the code above, or have you got something like:

((MyType)a).Amount += 10;

?

Your code should work, and here's a simple test program to show it
working:

using System;

class Test
{
float amount=0;
public float Amount
{
get { return amount; }
set { amount = value; }
}

static void Main()
{
Test a = new Test();
a.Amount += 10;
}
}

Could you product a similar short but complete program that
demonstrates the error?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote:
Have you *actually* got the code above, or have you got something like:


I found it. Account wasn't a class as I said, but a struct. I don't know
why, but I only needed to change "struct" to "class" to get it working. :-)
Thank you very much for the enlightening example anyway.

Gustaf

Nov 15 '05 #3

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

Similar topics

1
by: Jeroen van vliet | last post by:
Hello, im using visual basic 6.0 and i made an form where to insert names,street and an amount of money into an access database. Well every time when i insert an amount of money, the amount has...
1
by: Pif Paf | last post by:
I have a process, and my process wants to wait for input but only for a certain amount of time. The input might be coming from a Python file object (created with popen) or a TCP socket. What I...
2
by: Jeff Relf | last post by:
Hi all, In my .CPP file, I have a line like this: typedef struct { float Name, Amount; } ATypeDef ; Which I later use like this: ATypeDef XXX; which is like doing this: struct { float...
5
by: charlies224 | last post by:
Hi, I am using SQL 2000 and has a table that contains more than 2 million rows of data (and growing). Right now, I have encountered 2 problems: 1) Sometimes, when I try to query against this...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
4
by: soahil | last post by:
Thanks to Pragatiswain I have two table with follwing structure table no:1 BILL_DETAIl Name Null? Type ------------------------------- -------- ...
0
by: rabraham | last post by:
I have a commission report Im working on and it is causing to lose hair fast. I need help customizing this commission report. The current report has a couple conditions: Condition 1: Pay 2%...
3
by: rekcip | last post by:
Im currently doing a simple application using html and asp. I would like an application that displays basic services. The application should be designed with checkboxes to select various services...
1
by: HariKiran | last post by:
Hi, I want to know ,how to select more than 1 product and calculate its sum, and how to redirect this amount in paylpal for a single user.I'm using a check box to select 2 or more items...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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...

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.