Literal suffix for byte in .NET?

后端 未结 4 1431
生来不讨喜
生来不讨喜 2020-12-28 11:38

I am wondering if there is any way to declare a byte variable in a short way like floats or doubles? I mean like 5f and 5d. Sure I could write

4条回答
  •  旧巷少年郎
    2020-12-28 11:43

    As per MSDN you can declare a byte using a decimal, hexadecimal or binary literal.

    // decimal literal
    byte x = 5;
    
    // hex decimal literal
    byte x = 0xC5;
    
    // binary literal
    byte x = 0b0000_0101;
    

提交回复
热议问题