小编Sam*_*A C的帖子

C#变量和常量在溢出期间表现不同.

 const int cMax = int.MaxValue;
 int vMax = cMax;
 int int1;
 int int2;
 int1 = cMax + 10;//Checked amd throws error
 int2 = vMax+10;//Unchecked and Overflows at runTime
Run Code Online (Sandbox Code Playgroud)

这里可以看到,默认情况下会检查涉及常量的操作,而未选中涉及变量的操作并通过编译.

为什么编译行为会有所不同?

c# variables compiler-errors compilation constants

3
推荐指数
1
解决办法
49
查看次数

标签 统计

c# ×1

compilation ×1

compiler-errors ×1

constants ×1

variables ×1