Can anyone explain why the following doesn\'t compile?
byte b = 255 << 1
The error:
Constant value \'510\' can
The result of the << operator is an Int32, not what you put into it.
You need to cast the result of the shift, not the input. Additionally, it will produce an overflow (it is larger than a byte afterall), so you need to specify that you need an unchecked cast.
In other words, this will work:
Byte b = unchecked((Byte)(255 << 1));