To disable the overflow checking for certain expression, use the unchecked operator.
using System;
class Program
{
static void Main(string[] args)
{
int i = int.MinValue;
unchecked {
int result = i - 1;
Console.WriteLine("i=" + i);
Console.WriteLine("result=" + result);
Console.WriteLine("result is int.MaxValue:" + (result == int.MaxValue));
}
}
}
The output:
i=-2147483648
result=2147483647
result is int.MaxValue:True