>>>Hi,
>>>Given:
>>>private int scaleFactor = 1;
>>>public int ScaleFactor
>>> {
>>> get { return scaleFactor; }
>>> set
>>> {
>>> if (value == 0)
>>> {
>>> scaleFactor = scaleFactor == 1 ? -1 : 1;
>>> }
>>> else
>>> scaleFactor = value;
>>> }
>>> }
Why isn't i = -1 after
int i = --ScaleFactor;
>>
>>Where is
i ?
>
>Sorry. Not sure what you mean. If you mean where is the 'int i = --ScaleFactor' line then it's in a button click but I don't see the relevance
>Regards,
>Viv
I misunderstood i = -1 to be an assignment rather than i == -1 a comparaison
It's a weird construct with side effects - it's skipping zero
You decrement the ScaleFactor, a zero is in i, the zero gets assigned back to ScaleFactor, but the Set has a side effect and assigns it -1 instead of zero
The decrement operator does not 're-fetch' the value of ScaleFactor after assignment
If other values (2, 3, ...) are allowed, I would suggest this code, since you never know, without testing, when it was zero
--ScaleFactor;
int i = ScaleFactor;
Update: If you put a breakpoint on
int i = --ScaleFactor;
and step through it, you'll see how it works
Gregory