c# - Overflow exception is throwing- even the value exceeds the limit -


why following code gives output -2 instead throwing overflow exception?

 long x = long.maxvalue;  long y = long.maxvalue + x; 

the actual behaviour depends on project settings, unchecked etc. ensure overflow exception use checked, e.g.

 checked {    long x = long.maxvalue;    long y = long.maxvalue + x;  } 

Comments

Popular posts from this blog

json - Zend error Connection -

javascript - Trigger mouseenter when an animated element touches mouse -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -