What's wrong with this expression? Cannot implicitly convert type 'int' to 'byte'

后端 未结 5 1214
后悔当初
后悔当初 2020-12-19 02:29

I am getting the error \"Cannot implicitly convert type \'int\' to \'byte\'. An explicit conversion exists (are you missing a cast?)\". Doesn\'t byte + byte = byte

5条回答
  •  半阙折子戏
    2020-12-19 02:48

    C# widens all operands to int before doing arithmetic on them. So you'll need to cast it back to byte explicitly.

    http://msdn.microsoft.com/en-us/library/5bdb6693(VS.80).aspx

提交回复
热议问题