A Checked Block Example : checked « Data Type « C# / CSharp Tutorial






public class Program
{
  public static void Main()
  {
      checked
      {
          // int.MaxValue equals 2147483647
          int n = int.MaxValue;
          n = n + 1 ;
          System.Console.WriteLine(n);
      }
  }
}








2.48.checked
2.48.1.Using checked and unchecked
2.48.2.Numeric Addition overflow for a byte
2.48.3.Mark code block as checked
2.48.4.A Checked Block Example