unchecked

suggest change

The unchecked keyword prevents the compiler from checking for overflows/underflows.

For example:

const int ConstantMax = int.MaxValue;
unchecked
{
    int1 = 2147483647 + 10;
}
int1 = unchecked(ConstantMax + 10);

Without the unchecked keyword, neither of the two addition operations will compile.

When is this useful?

This is useful inside a checked context, where skipping the overflow check can be faster, and when wraparound is the desired behavior (for instance, when generating a hash code).

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents