static void Main(string args)
byte result = 255;
result2 = (byte) (result + result1);
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. http://msdn.microsoft.com/en-us/library/5bdb6693.aspx