Export (0) Print
Expand All
3 out of 7 rated this helpful - Rate this topic

Checked and Unchecked (C# Reference)

C# statements can execute in either checked or unchecked context. In a checked context, arithmetic overflow raises an exception. In an unchecked context, arithmetic overflow is ignored and the result is truncated.

  • checked   Specify checked context.

  • unchecked   Specify unchecked context.

If neither checked nor unchecked is specified, the default context depends on external factors such as compiler options.

The following operations are affected by the overflow checking:

  • Expressions using the following predefined operators on integral types:

    ++      - (unary)   +   -   *   /

  • Explicit numeric conversions between integral types.

The /checked compiler option lets you specify checked or unchecked context for all integer arithmetic statements that are not explicitly in the scope of a checked or unchecked keyword.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.