Max HEX value for long type

前端 未结 4 1887
情书的邮戳
情书的邮戳 2021-01-21 23:38

I have ported Java code to C#. Could you please explain why I have compile-time error in the follow line (I use VS 2008):

    private long l = 0xffffffffffffffff         


        
4条回答
  •  孤街浪徒
    2021-01-21 23:50

    Assuming you aren't worried about negative values, you could try using an unsigned long:

    private ulong l = 0xffffffffffffffffL;
    

    In Java the actual value of l would be -1, because it would overflow the 2^63 - 1 maximum value, so you could just replace your constant with -1.

提交回复
热议问题