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