10.4. checked and unchecked operators and statements

The checked keyword is useful for detecting overflows [5] in integral-type arithmetic operations and conversions.

[5] An overflow results when you are trying to store an integer value which is beyond the range of the integral variable. For example, the short type's range is only -32 768 to +32 767. An attempt to store a value greater than 32 767 into a short type causes an overflow. An attempt to store a value smaller than -32 768 into a short type causes an underflow. No distinction is made between underflow and overflow in this book. When I use the term 'overflow', I am referring to both overflow and underflow scenarios.

10.4.1. The checked keyword

The checked keyword can be used in one of ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.