CSharp - Integral types Overflow

Introduction

Arithmetic operations on integral types can overflow.

By default, overflow happens silently and no exception would be thrown.

The following code decrements the minimum possible int value results in the maximum possible int value:

Demo

using System;
class MainClass/*from   ww  w.  j a  v a 2  s  . c om*/
{
   public static void Main(string[] args)
   {
     int a = int.MinValue;
     a--;
     Console.WriteLine (a == int.MaxValue); // True

   }
}

Result