我可以使用下面的方法将 Guid String 转换为 BigInteger。如何将 BigInteger 转换回 Guid 字符串。
using System;
using System.Numerics;
class Class1
{
public static BigInteger GuidStringToBigInt(string guidString)
{
Guid g = new Guid(guidString);
BigInteger bigInt = new BigInteger(g.ToByteArray());
return bigInt;
}
static void Main(string[] args)
{
string guid1 = "{90f0fb85-0f80-4466-9b8c-2025949e2079}";
Console.WriteLine(guid1);
Console.WriteLine(GuidStringToBigInt(guid1));
Console.ReadKey();
}
}
最佳答案
请检查:
public static Guid ToGuid(BigInteger value)
{
byte[] bytes = new byte[16];
value.ToByteArray().CopyTo(bytes, 0);
return new Guid(bytes);
}
关于c# - 将 Guid 字符串转换为 BigInteger,反之亦然,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54353695/