Reputation: 55
Use int to test if below 0 . uint in c# wraps around to a huge number once it goes below 0, this is in all programming languages.
Upvotes: 0
Views: 1136
Reputation: 19043
You can do it like this
uint i = 0;
i = checked(i - 1);
This will throw System.OverflowException
. Though it will not stay zero, at least you will be sure that no overflow happened.
Upvotes: 4
Reputation: 55
I just use ordinary int instead of uint, and check if its < 0... problem solved
Upvotes: -2