C# and overflow

C# No Comments »

In my previous post Implemented integer overflow class, I off-handedly mentioned that C# appeared to retain C’s overflow for semantics for addition. It appears that C# supports two contexts, checked and unchecked, in which an overflow in integer arithmetic generates or does not generate an exception, respectively [documentation]. Furthermore, there is a compiler flag, /checked, which may be used to specify the default context for integer arithmetic statements [documentation].

Kudos to the developers of C# for the forethought and attention to detail.

Perhaps in the future they should consider making /checked the default for security reasons.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in