ThickBook ThickBook - 1 month ago 15
C# Question

Difference of using int and uint and when to use

What is the difference between using int and uint? All the examples I have seen so far are using int for integers. Any advantage of using uint? Thanks.

Answer

uint means unsigned int, you can use it for a 0 .. +4G range
where the normal (signed) int has a -2G .. +2G range.

When to use it? Almost never. It is not a CLS compliant type so you should never use it in the public interface of an assembly. Not all .NET languages can handle it.

Their main use is in P/Invoke to unmanaged code and some rare bitmask situations. In .NET, we do most bitmasking with normal signed ints.

Comments