Checked Operator

Definition - What does Checked Operator mean?

A checked operator, in C#, is an operator used to enforce overflow checking for integral-type arithmetic operations and conversions at run time. Checked operators are used to detect overflow errors that can occur at run time for arithmetic operations that result in too of a large number for the number of bits allocated to the data type of the result in use.

Although there are other options for overflow checking, such as compiler switches and execution environment configurations, checked operators provide a programmatic way to achieve the same and ensure that overflow is handled.

Techopedia explains Checked Operator

The operations that are affected by overflow checking using checked operators are those that use predefined operators, including "++", "--", and binary operators like "+", "-", "/", "*", and explicit numeric conversions from one integral type to another, or from float/double to integral type. The output of the operation will be based on the operands. For expressions that contain only constant values, overflow can be detected by the compiler and displayed as an error. For expressions consisting of one or more than one non-constant value, the overflow will be checked during runtime and an exception (System.OverflowException) will be raised.

In contrast to overflow checking for signed integer arithmetic in C/C++ in which it is "implementation defined", C# has improved the way overflow check is controlled. Checked operator is used to execute C# statements in a checked context such that an exception is raised when an arithmetic overflow occurs. It forces the Common Language Runtime (CLR) to handle stack overflow situations while performing operations on integer types that can result in values outside the bounds of the data type.

A checked operator affects the overflow checking context for operations that are textually specified within parentheses. It does not affect any function invoked as a result of the evaluation of the contained expression.

This definition was written in the context of C#
Share this:

Connect with us

Email Newsletter

Join thousands of others with our weekly newsletter

The 4th Era of IT Infrastructure: Superconverged Systems
The 4th Era of IT Infrastructure: Superconverged Systems:
Learn the benefits and limitations of the 3 generations of IT infrastructure – siloed, converged and hyperconverged – and discover how the 4th...
Approaches and Benefits of Network Virtualization
Approaches and Benefits of Network Virtualization:
Businesses today aspire to achieve a software-defined datacenter (SDDC) to enhance business agility and reduce operational complexity. However, the...
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.