Check Vs Uncheck #csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Throw
{
class Program
{
static void Main(string[] args)
{
int i =int.MaxValue ;
int j = int.MaxValue;
int z = i + j;//-2,默认就是int z = unchecked(i+j);
Console.WriteLine(z);
try
{
int x = checked(i + j);
}
catch (OverflowException ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadKey();
}
}
}