When I write this code
Console.WriteLine(-1 * int.MinValue);
or
int a = -1 * -2147483648;
I get an error
The operation overflows at compile time in checked mode.
Is there compile time check especially for this value?
or is it counting all written expressions real time?
The compiler is able to perform the (multiplication) calculation at compile time rather than runtime, so it does.
Since
-1 * int.MinValue(-1 * -2,147,483,648, thus 2,147,483,648) is greater thanint.MaxValue(2,147,483,647) it gives you your compile error.To prove that it isn’t special casing your exact statement, try:
and you will get the same behaviour.