If numeric expression contains operands (constants and variables) of different numeric types, are operands promoted to larger types according to the following rules:
- if operands are of types
byte
,sbyte
,char
,short
,ushort
, they get converted toint
type - If one of the operands is
int
, then all operands are converted toint
- if expression also contains operands of types
uint
andint
, then all operands are converted tolong
- If one of operands is
long
, then all operands are converted tolong
- if expression contains operands of type
ulong
andlong
, then operands are converted tofloat
- If one of the operands is
float
, then all operands are converted tofloat
- if one of operands is
double
, then all operands are converted todouble
Assuming numeric expressions contains operands of different types, will all operands first get converted to a single numeric type, and only then will the runtime try to compute the result? For example, if variables b1
and b2
are of byte
type, while i1
is of int
type, will b1
and b2 get
converted to int prior to computing (b1+b2)
:
int i2=(b1+b2)+i1