Mark code block as checked : Checked : Data Type C# Examples


C# Examples » Data Type » Checked »

 

Mark code block as checked









    
using  System;

class  MainClass
{
        public  static  void  Main()
        {
                byte  val1  =  200;
                byte  val2  =  201;
                byte  sum  =  (byte)  (val1  +  val2);      //  no  exception
                checked
                {
                        byte  sum2  =  (byte)  (val1  +  val2);            //  exception
                }
        }
}
    
   
  
   



Output

Unhandled Exception: System.OverflowException: Arithmetic operation resulted in an overflow.
   at MainClass.Main()


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Checked