In an unchecked context, if an expression produces a value that is outside the range of the destination type, the result is truncated. For example:
unchecked
{
int val = 2147483647 * 2;
} Because the calculation above is performed in an unchecked block, the fact that the result is too large for an integer is ignored, and val is assigned the value -2. By default, overflow detection is enabled, which has the same effect as using checked.
In the example above, had unchecked been omitted, a compilation error would occur because the expression uses constants and the result is known at compile time. The unchecked keyword also suppresses overflow detection for non-constant expressions, which otherwise result in OverflowException at runtime.
The unchecked keyword can also be used as an operator, like this:
public int UncheckedAdd(int a, int b)
{
return unchecked(a + b);
}