Compound assignment operators e.g +=
and -=
and <<=
, etc have a implicit type cast in their operation.
In other words.
byte x = 1;
x <<= 4;
is equal to:
byte x = 1;
x = (byte)(x << 4);
when compiled.
The left-shift operation still promotes the variables appropriately (in the case of byte
to an int
) but the compound assignment operator casts it for you.