How to use C#'s ternary operator with two byte values?

后端 未结 4 1675
悲&欢浪女
悲&欢浪女 2020-12-18 00:50

There doesn\'t seem to be a way to use C#\'s ternary operator on two bytes like so:

byte someByte = someBoolean ? 0 : 1;

That code currentl

4条回答
  •  情歌与酒
    2020-12-18 01:18

    You could always do:

    var myByte = Convert.ToByte(myBool);
    

    This will yield myByte == 0 for false and myByte == 1 for true.

提交回复
热议问题