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
Post a Comment