Can someone tell why I am getting 0 in this?

        static void Main(string[] args)
            byte result = 255;
            byte result2=2;
            byte result1=1;

                result2 = (byte) (result + result1);

            catch(Exception e)
                Console.WriteLine("Error : ");

I am getting output


But not the catched exception.

When I debugged the code, I got, that in result2 = (byte) (result + result1);, result2 becomes 0 automatically.

Is there a reason you are using byte instead of int? I have never tried adding bytes together before. Not sure if that is related to your problem though

Yes I wanted to know the use of Checked and Unchecked by doing this.

I suspect it is because byte is 0-255, so you are creating an INT of 256 and casting to byte which gets you back to 0.

^^ Exactly, Byte is 0 to 255 and your computation will therefore result in an overflow.