Tag: 语言 律师

是否定义了C#/ .NET签名的整数溢出行为?

在未经检查的上下文中,将一个加到一个值为2147483647的整数,保证导致-2147483648? 例如,使用以下代码 const int first = int.MaxValue; int second = first; if ( second >= first ) { Console.WriteLine( “First check” ); } second++; if ( second >= first ) { Console.WriteLine( “Second check” ); } 在C ++中,对于要打印的“First check”和“Second check”都是完全有效的,因为优化器可以重用第一次检查的结果。 C#也是如此吗?