Search code examples
c#integerbyteadditionoperation

additing the same numbers in int and byte, why results are different? c#


When it converts to int implicitly - the result is obvious, but when it adds bytes - it`s different, why? enter image description here


Solution

  • Your code just overflows byte — it supports integer values from 0 to 255. You should use at least short.