这是我的代码。
string strTemp = "";
for (int i = input1; i <= input2; i++)
{
strTemp = Math.Abs(i).ToString();
//other stuff here
}
当 input1 的值为 -2147483648 时出现错误
Negating the minimum value of a twos complement number is invalid.
我有点明白这是由于溢出异常造成的。 但是我该如何克服呢?请提出任何建议。
最佳答案
+2147483648
大于 int
的最大值,即 231 - 1。
相反,您可以使用 long
;它的最大值是 263 - 1。
如果这对你来说还不够;使用 BigInteger
。
关于c# - 无法获得 Math.Abs(-2147483648) 的值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16131544/