在做数值运算时加入显示转换可能溢出报错,若不想检测溢出情况则加入关键字unchecked即可
public static void Main(string[] args) { Console.WriteLine("Hello World!"); // TODO: Implement Functionality Here unchecked{ int x=260; byte z=(byte)x; Console.Write("Press any key to continue . . . "+z); //结果为z=4不报溢出错误 } Console.ReadKey(true); }