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   w  ww.  j ava  2s.co m*/
{
   public static void Main(string[] args)
   {
     int a = int.MinValue;
     a--;
     Console.WriteLine (a == int.MaxValue); // True

   }
}

Result