What is the output of the following code?
using System; class MainClass { public static void Main(string[] args) { int x = int.MaxValue + 1; Console.WriteLine(x); } }
int x = int.MaxValue + 1; // Compile-time error
Regardless of the /checked compiler switch, expressions evaluated at compile time are always overflow-checked.
You can turn off the check by using the unchecked operator.
int y = unchecked (int.MaxValue + 1); // No errors