Overflow

Lets say you assign value 255 to a byte data type. If you increment that value and try to get that value, it would show zero, because, the biggest value that a byte can take is, 255. If you increment it more, it would go beyond 255 and it doesnt know how to handle it. This is called overflowing.

Ex: byte number = 255;

number = number + 1;

This would result a zero value. Either use keyword “checked” or change data type of number to int or something else.

checked

{

byte number = 2;

number = number +1;

}

Last updated