C#: How to convert long to ulong

后端 未结 5 1818
旧巷少年郎
旧巷少年郎 2021-02-20 08:28

If i try with BitConverter,it requires a byte array and i don\'t have that.I have a Int32 and i want to convert it to UInt32.

In C++ there was no problem with that.

5条回答
  •  深忆病人
    2021-02-20 09:12

    To convert a long to a ulong, simply cast it:

    long a;
    ulong b = (ulong)a;
    

    C# will NOT throw an exception if it is a negative number.

提交回复
热议问题