CSharp - What is the output: Overflow constant expressions?


What is the output of the following code?

using System;
class MainClass
   public static void Main(string[] args)
       int x = int.MaxValue + 1;


Click to view the answer

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