The plus operator implicitly up casts the shorts to ints and generates an int
result which can't be implicitly down cast back o a short. So you need to
explicitly cast the sum (short)(a+b). This is like telling the compiler "I
know what I'm doing and it is OK, trust me.".
--
Thanks
Jonny
"ny***********@gmail.com" wrote:
The following code result in the following compilation error: Error 1
Cannot implicitly convert type 'int' to 'short'. An explicit conversion
exists (are you missing a cast?)
short a = 1;
short b = 2;
short result = a + b;
Can anyone explain why??