In assumption C# was strongly typed I was a little supprised about the following:
short (C# Reference) https://msdn.microsoft.com/nl-nl/library/ybs77ex4.aspx
Does not compile: short x = 6, y = 45; short z = x + y;
Compiles short x = 6, y = 45; int z = x + y; // result is Struct.Int32
Compiles short x = 6, y = 45; var z = x + y; // var is Struct.Int32
Compiles short x = 6, y = 45; var z = (short)(x + y); // result Struct.Int32 is cast to struct.Int16
Then Resharper suggested as follows and compiles:
const short a = 6;
const short b = 45;
short c = a + b; // result is Struct.Int16 without any casting
although when var is used
const short a = 6;
const short b = 45;
var c = a + b; // var result is Struct.Int32 not Struct.Int16
What I do not get is why the operation can be stored in short when using const short and not when using short as variable. Secondly when var is used on operation of const short it also results into int and not short what imo means c# secretly casts it when short is stricly defined.
Can anyone elaborate why this is designed as it is?