Information Technology Reference
In-Depth Information
For simple assignment, the expression to the right of the operator is evaluated and its
value is assigned to the variable on the left.
int x;
x = 5;
x = y * z;
The types of objects that can be on the left side of an assignment operator are the follow-
ing. They will be discussed later in the text.
￿
Variables (local variables, fields, parameters)
￿Proper ies
￿
Indexers
￿Events
Compound Assignment
Frequently, you'll want to evaluate an expression and add the results to the current value of a
variable, as shown:
x = x + expr ;
The compound assignment operators allow a shorthand method for avoiding the repeti-
tion of the left-side variable on the right side under certain common circumstances. For
example, the following two statements are exactly equivalent semantically, but the second is
shorter and just as easy to understand.
x = x + (y - z);
x += y - z;
The other compound assignment statements are analogous:
Notice the parentheses.
x *= y - z; // Equivalent to x = x * (y - z)
x /= y - z; // Equivalent to x = x / (y - z)
...
Search WWH ::




Custom Search