<21天學通C#>使用unchecked使得命令編輯器不對代碼進行檢查,使用checked對代碼進行檢查

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;編輯器

namespace 使用unchecked使得命令編輯器不對代碼進行檢查
{
class Program
{
static void Main(string[] args)
{
int val1 = 2147483647;
int val2 ;
unchecked
{
val2 = val1 + 1;
}
Console.WriteLine("val1 is {0}", val1);
Console.WriteLine("val2 is {0}", val2);
Console.WriteLine("按任意鍵退出");
Console.ReadKey();
}
}
}spa

改成checked:3d

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;blog

namespace 使用unchecked使得命令編輯器不對代碼進行檢查
{
class Program
{
static void Main(string[] args)
{
int val1 = 2147483647;
int val2 ;
checked
{
val2 = val1 + 1;
}
Console.WriteLine("val1 is {0}", val1);
Console.WriteLine("val2 is {0}", val2);
Console.WriteLine("按任意鍵退出");
Console.ReadKey();
}
}
}string

 

相關文章
相關標籤/搜索