W
wizofaus
Compiles:
short a = 1;
a += 2;
Does not:
short a = 1;
a = a + 2;
(Cannot implicitly convert type 'int' to 'short').
Does this not strike anyone as little incongruent?
I assume the rules for type promotion after arithmetic are documented
somewhere, but it appears to be...
[sbyte|short|int] + [byte|short|int] = int // true for + - * /
[sbyte|short|int|long] + long = long
[sbyte|short|int|long|float] + float = float
[sbyte|short|int|long|float|double] + double = double
(unsigned types behave as per their signed relatives)
Even
a = a + (short)2;
does not compile; you need:
a = (short)(a + 2);
As a C++ programmer, the return of the old "C" cast syntax (which I
haven't used for over 5 years) is definitely the least appealing part
of C#, but there seems to be no way to avoid it.
short a = 1;
a += 2;
Does not:
short a = 1;
a = a + 2;
(Cannot implicitly convert type 'int' to 'short').
Does this not strike anyone as little incongruent?
I assume the rules for type promotion after arithmetic are documented
somewhere, but it appears to be...
[sbyte|short|int] + [byte|short|int] = int // true for + - * /
[sbyte|short|int|long] + long = long
[sbyte|short|int|long|float] + float = float
[sbyte|short|int|long|float|double] + double = double
(unsigned types behave as per their signed relatives)
Even
a = a + (short)2;
does not compile; you need:
a = (short)(a + 2);
As a C++ programmer, the return of the old "C" cast syntax (which I
haven't used for over 5 years) is definitely the least appealing part
of C#, but there seems to be no way to avoid it.