将.NET long转换为无符号的8字节整数

时间:2010-05-26 00:37:19

标签: .net long-integer unsigned-integer

为了在Active Directory中设置值,我想将long转换为无符号的8字节整数,以便分配给AD属性。

我该怎么做?

2 个答案:

答案 0 :(得分:2)

如果long为负数并且可能导致OverflowException,则简单转换可能会导致问题。您需要使用unchecked语法来确保正确转换。

ulong myUnsignedValue = unchecked( (ulong)originalLongValue );

答案 1 :(得分:0)

long投射到ulong

更多信息here

相关问题