miscellaneous
Difference between a = a + b and a += b expressions.
The Difference: Implicit Casting
- a = a + b:
- Performs addition and requires manual casting if types differ.
- Example:
byte a = 10; a = a + 5; // Compilation Error (Result is int) a = (byte)(a + 5); // Correct
- a += b:
- Performs the operation and automatically casts the result to the type of 'a'.
- Example:
byte a = 10; a += 5; // Valid. Automatically casts result to byte.