Checked vs Unchecked C#

Reference: msdn

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.

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.

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.

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.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.

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s