Convert GUID to Numeric Equivalent

后端 未结 2 1558
无人共我
无人共我 2021-01-22 03:22

I\'ve been asked to export a list of users from ActiveDirectory, and Convert the GUIDs to a numeric equivalent for display (so I\'ll .ToString that after). I\'ve done some searc

2条回答
  •  后悔当初
    2021-01-22 04:05

    "Numeric" doesn't make sense in VB w.r.t Guid. There is no 128-bit numeric types in .net. The only 128-bit type is Decimal; but that doesn't seem to make sense to convert a Guid to a Decimal. I would simply use ToByteArray and display the byte values as hex.

    Alternatively, make sure the last byte in the array given to BigInteger is zero to get a postive value. e.g.::

    var bytes = Guid.NewGuid().ToByteArray(); 
    Array.Resize(ref bytes, 17); 
    var bigInt = new BigInteger(bytes);
    var value = bigInt.ToString();
    

提交回复
热议问题