首页 > 其他 > 详细

checked,unchecked

时间:2016-06-04 00:26:28      阅读:251      评论:0      收藏:0      [点我收藏+]

static void Main(string[] args)
{
byte b1 = 100;
byte b2 = 250;
//Checked
try
{
byte sum = checked ((byte) Add(b1, b2));
Console.WriteLine(sum);
Console.ReadLine();
}
catch (OverflowException Ex)
{
Console.WriteLine(Ex.Message);
}
}

static int Add(int x, int y)
{
return x + y;
}

 

unchecked

{

byte sum=(byte)(100+200);

Console.WriteLine(sum);

}

 

算术运算导致溢出。

checked,unchecked

原文:http://www.cnblogs.com/Fred1987/p/5557877.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!