decimal d = 2;
int i = (int) d;
I've seen this several times in which parentheses are wrapped around data types.
Why not just use int i = int d;?
decimal d = 2;
int i = (int) d;
I've seen this several times in which parentheses are wrapped around data types.
Why not just use int i = int d;?
The usage of
(int)is calledcasting (or, type-casting). It is essentially telling that,interpretconvert the value ofdasto anint(integer) and store it intoi.In other words, it is a way of converting a type to another one (subject to validity of the conversion).
BTW,
int i = int d;, as is, is not a valid statement.