using System;
namespace ConsoleApplication_C_Sharp
{
class Program
{
static void Main(string[] args)
{
checked
{
short n = 0;
for (int i = 0; i < short.MaxValue; i++)
{
n++;
}
for (int i = 0; i < short.MaxValue; i++)
{
n++; // overflow error
}
}
}
}
}
/*
run:
Unhandled Exception: System.OverflowException: Arithmetic operation resulted in
an overflow.
at ConsoleApplication_C_Sharp.Program.Main(String[] args) in d:\Conso
leApplication_C_Sharp\ConsoleApplication_C_Sharp\Program.cs:line 18
*/