1

For the purposes of setting a value in Active Directory I would like to convert a long to an unsigned 8-byte integer, for assignment to an AD property.

How can I do this?

Ben Aston
  • 53,718
  • 65
  • 205
  • 331

2 Answers2

2

A simple cast can cause problems if the long is negative and may result in an OverflowException. You'll need to use the unchecked syntax to ensure it is cast properly.

ulong myUnsignedValue = unchecked( (ulong)originalLongValue );
Josh Stodola
  • 81,538
  • 47
  • 180
  • 227
Paul Alexander
  • 31,970
  • 14
  • 96
  • 151
0

Cast the long to a ulong.

More info here.

Community
  • 1
  • 1
Ben Aston
  • 53,718
  • 65
  • 205
  • 331