Re: why does adding 2 bytes together result in an int?



Kevin Spencer <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
This is because the devleopers of the platform have decided that the return
type of the + operator for the byte type should be an integer.

Not quite. There *aren't* any + operators for the byte type. These are
the integer addition operators:

int operator +(int x, int y);
uint operator +(uint x, uint y);
long operator +(long x, long y);
ulong operator +(ulong x, ulong y);

When it looks like you're adding two bytes, you're actually implicitly
converting each of them to an integer, then adding the two integers
together.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages