Overflow exception is throwing- even the value exceeds the limit
问题 Why the following code Gives output as -2 instead for throwing overflow exception ? long x = long.MaxValue; long y = long.MaxValue + x; 回答1: The actual behaviour depends on project settings, unchecked etc. To ensure overflow exception use checked , e.g. checked { long x = long.MaxValue; long y = long.MaxValue + x; } 回答2: Presumably because you're executing it in an unchecked context. Arithmetic on the primitive integer types can execute in a checked or unchecked context. Operations which