ThickBook ThickBook - 1 year ago 85
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download