For example:
int value = Int32.MaxValue;
unchecked
{
value += 1;
}
In what ways would this be useful? can you think of any?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
uncheckedwhen:The latter is useful when computing a hash code – for example, in Noda Time the project is built with checked arithmetic for virtual everything apart from hash code generation. When computing a hash code, it’s entirely normal for overflow to occur, and that’s fine because we don’t really care about the result as a number – we just want it as a bit pattern, really.
That’s just a particularly common example, but there may well be other times where you’re really happy for
MaxValue + 1to beMinValue.