9.4. Unsigned types in C#

Unsigned types are types which cannot store values in the negative range (hence unsigned – the values stored are always positive). [4] The unsigned integral types in C# are: byte (not ubyte!), ushort, uint, and ulong. [5]

[4] The reason for unsigned types is that you can store twice as many values in the positive range with the same number of bits because one bit is no longer required for storing the sign. Signed types always 'waste' one bit for determining if the value stored is positive or negative. There is no way in Java we can 'save' on the wasted bit, even if we know for certain that a particular value can never be negative. Anyway, this is probably not a significant issue given the amount of memory available to ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.