Skip to content

C# Feature - checked operators

The checked keyword and checked context make arithmetic overflow throw an exception instead of wrapping silently.

C# 1.0 (2002)

int max = int.MaxValue;
int wrapped = max + 1;
int max = int.MaxValue;
int safe = checked(max + 1);
  • Use checked in numeric code where overflow is a bug.
  • Use unchecked explicitly when wraparound is intentional.