JuLiE Dxer <Ms*****@verizon.net> wrote:
Perhaps, I skipped over learning this particular tidbit.
I ran across an odd error while trying to add to ushort variables
together and assigning it to a 3rd ushort variable.
I get this compiler error:
error CS0029: Cannot implicitly convert type 'int' to 'ushort'
code is basically this
ushort u1, u2, u3;
u1 = 3;
u2 = 5;
u3 = u1 + u2;
Does ushort math always an int object?
Sort of. In fact, you can't do maths with ushorts. What you *can* do
maths on is ints, and that's what happens with the above. You've
effectively got:
u3 = (int)u1 + (int)u2;
The only integer addition operators defined are:
int operator +(int x, int y);
uint operator +(uint x, uint y);
long operator +(long x, long y);
ulong operator +(ulong x, ulong y);
The normal (and somewhat long-winded) operator overload resolution is
applied to select the first of these as the best overload, and that's
the one which is used.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too