In C# should I use uint or int for values that are never supposed to be negative?
- by Hamish Grubijan
Suppose that the MaxValue of (roughly :) ) 2^31 vs 2^32 does not matter.
On one hand, using uint seems nice because it is self-explanatory, it indicates (and promises?) that some value may never be negative. However, int is more common, and a cast is often inconvenient. One can just use int and always supplement it with code contracts (everyone has moved to .Net 4.0 by now, right?) Standard libraries do use int for Length and Size properties, even though those should never be negative. So, is it obvious to you that int is better than uint most of the time, or is it more complicated?
Please ask questions if you find that this question is not clearly stated.
Thanks.