Errore del compilatore CS0220

Aggiornamento: novembre 2007

Messaggio di errore

Operazione in overflow in fase di compilazione in modalità checked.
The operation overflows at compile time in checked mode

In modalità checked, ovvero l'impostazione predefinita, è stata rilevata un'operazione che ha provocato una perdita di dati. Per risolvere l'errore, correggere gli input dell'assegnazione oppure utilizzare unchecked. Per ulteriori informazioni, vedere Checked e Unchecked (Riferimenti per C#).

Il seguente codice di esempio genera l'errore 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());
   }
}