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)
这里可以看到,默认情况下会检查涉及常量的操作,而未选中涉及变量的操作并通过编译.
为什么编译行为会有所不同?