Export (0) Print
Expand All

/checked (Check Integer Arithmetic)

/checked[+ | -]

Remarks

The /checked option specifies whether an integer arithmetic statement that is not in the scope of the checked or unchecked keywords and that results in a value outside the range of the data type shall cause a run-time exception.

An integer arithmetic statement that is in the scope of the checked or unchecked keywords is not subject to the effect of the /checked option.

If an integer arithmetic statement that is not in the scope of the checked or unchecked keywords results in a value outside the range of the data type, and /checked+ (/checked) is used in the compilation, then that statement will cause an exception at run time. If /checked- is used in the compilation, then that statement will not cause an exception at run time.

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Setting Visual C# Project Properties.
  2. Click the Configuration Properties folder.
  3. Click the Build property page.
  4. Modify the Check for Arithmetic Overflow/Underflow property.

To set this compiler option programmatically

See CheckForOverflowUnderflow Property.

Example

Compile t2.cs and specify that an integer arithmetic statement that is not in the scope of the checked or unchecked keywords and results in a value outside the range of the data type will cause an exception at run time.

csc t2.cs /checked

See Also

C# Compiler Options

Show:
© 2014 Microsoft