更新:2007 年 11 月
错误消息
在检查模式下,运算在编译时溢出下面的示例生成 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());
   }
} | |