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

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

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