Why int.MaxValue – int.MinValue = -1?

int.MaxValue - int.MinValue = a value which int cannot hold. Thus, the number wraps around back to -1.

It is like 2147483647-(-2147483648) = 4294967295 which is not an int

Int32.MinValue Field

The value of this constant is -2,147,483,648; that is, hexadecimal
0x80000000.

And Int32.MaxValue Field

The value of this constant is 2,147,483,647; that is, hexadecimal
0x7FFFFFFF.

From MSDN

When integer overflow occurs, what happens depends on the execution
context, which can be checked or unchecked. In a checked context, an
OverflowException is thrown. In an unchecked context, the most
significant bits of the result are discarded and execution continues.
Thus, C# gives you the choice of handling or ignoring overflow.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)