tags:

views:

99

answers:

2

I just started reading up on the C# language, and one of the first sections in my reading material is, naturally, variables and types.

In short order I came across the integral types table, which listed sbyte, byte, short, ushort, int, uint, long, ulong and char. The exception to the pairing here is char, so let's disregard it and have a look at the others.

The first pair, byte, prefixes the signed version with an "s", and leaves the unsigned version without a prefix. But for all the other pairs, the relation is reversed... the signed version is without prefix and the unsigned has a "u" prefix.

Is there a reason for this that I should be aware of, or is this just a design quirk?

Link for reference: http://msdn.microsoft.com/en-us/library/exx3b86w.aspx

+4  A: 

I'm guessing that byte is probably much more common to be used as an unsigned type rather than a signed type.

Spoike
+11  A: 

Bytes are conventionally treated as a pattern of bits rather than a normal number, and the "standard" values for a byte are 0 to 255. The signed version of byte is the abnormal case, with values treated as -128 to 127.

For all other numeric types the "standard" values are signed, as this tallies with our day-to-day intuitions about numbers (ie, that they can be negative as well as positive). For numeric types, the unsigned versions are the abnormal case.

(I don't think that I've ever used sbyte in any real-world code, and I use int, long etc much more often than I use their unsigned counterparts.)

LukeH
Sounds logical I suppose. :)Thank you!
grimman