This is the simple example of a c# program, in which we can see how to use checked statement
and also how it works.
The checked statement force c# to raise the exception error
whenever stack underflow or overflow occurred
due to the integral type arithmetic or conversion issue.
ENJOY CODING !!!!
_________________________________________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Checked_statement
{
class PostSlush
{
public static void Main(string[] args)
{
int no;
// assign maximum value
no = int.MaxValue;
try
{
checked
{
// forces stack overflow exception
no = no + 1;
Console.WriteLine(no);
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
Console.ReadLine();
}
}
}
Output :

