Compiler Error CS0220

The operation overflows at compile time in checked mode

An operation was detected by checked, which is the default, and a data loss resulted. Either correct the inputs to the assignment or use unchecked to resolve this error. For more information, see Checked and Unchecked (C# Reference).

The following sample generates CS0220:

// CS0220.cs
using System;

class TestClass
{
   const int x = 1000000;
   const int y = 1000000;

   public int MethodCh()
   {
      int z = (x * y);   // CS0220
      return z;
   }

   public int MethodUnCh()
   {
      unchecked
      {
         int z = (x * y);
         return z;
      }
   }

   public static void Main()
   {
      TestClass myObject = new TestClass();
      Console.WriteLine("Checked  : {0}", myObject.MethodCh());
      Console.WriteLine("Unchecked: {0}", myObject.MethodUnCh());
   }
}