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

javascript - Trigger mouseenter when an animated element touches mouse -

json - Zend error Connection -

java - Using Spring @Transactional with a combination of readOnly and write, when does this entity get committed? -