Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile time error on addition of two short variable [C#] [duplicate]

Tags:

c#

Possible Duplicate:
Integer summing blues, short += short problem

I have summarized my problem into following code snippet.I have two short vaiable and I am adding these two variable into another short variable,but I am getting compile time error.Why is it so?

 1.short x = 1, y = 1;
 2.short z = x + y;   

Compile time error at line 2 EDIT:

If short+short=int

then why int+int !=long
like image 682
santosh singh Avatar asked Dec 22 '22 15:12

santosh singh


1 Answers

By specification short + short -> int. Do short z = (short)(x + y);

Best answer is given by Eric Lippert here: Integer summing blues, short += short problem

like image 184
Andrey Avatar answered Mar 11 '23 20:03

Andrey