11 Vote

C#/.NET: Difference between int and uint

Question by Guest | 2016-11-02 at 18:18

I know about the difference between the data types short, int and long (16-bit, 32-bit and 64-bit integer numbers) in C#. However, recently I have recognized some other integer types in an example code: ushort, uint and ulong - so that seems to be the normal types with an additional prepended u.

What are those types supposed to be? I have played a bit with them and they seem to work like usual integers. So, where is the difference?

1Best Answer1 Vote

The "u" is standing for "unsigned". So, those types are integers that you do not have a sign and therefore can only hold positive values.

The advantage of those unsigned integers is that they can accept much higher numbers at the same bit length.

Here you can see the minimum and maximum values of the types:


As you can see, at the same bit length, the unsigned integers can take twice as large values. You should always use such types in a case in which you know that a value will never become negative but can become very large (and therefore can reach the limits of the available range).
2016-11-03 at 16:03

ReplyPositive Negative

Related Topics

Java: Declare unsigned Integer

Question | 2 Answers

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own article on askingbox.com. That’s how it’s done.