gpt4 book ai didi

c# - 将 byte[] 或对象转换为 GUID

转载 作者:IT王子 更新时间:2023-10-29 04:45:58 25 4
gpt4 key购买 nike

我为对象数据类型分配了一些值,例如,

object objData =dc.GetDirectoryEntry().Properties["objectGUID"].Value;

这个对象像 {byte[16]} 一样返回值
[0]: 145
[1]: 104
[2]: 117
[3]: 139
[4]: 124
[5]: 15
[6]: 255
[7]: 68
[8]: 142
[9]: 159
[10]: 208
[11]: 102
[12]: 148
[13]: 157
[14]: 179
[15]: 75

然后我将这个对象转换为byte[],就像

byte[] binaryData = objData as byte[];

它也会像这样返回, {字节[16]}
[0]: 145
[1]: 104
[2]: 117
[3]: 139
[4]: 124
[5]: 15
[6]: 255
[7]: 68
[8]: 142
[9]: 159
[10]: 208
[11]: 102
[12]: 148
[13]: 157
[14]: 179
[15]: 75

然后我将 byte[] 中的十六进制值转换为

string strHex = BitConverter.ToString(binaryData);

它将像 **91-68-75-8B-7C-0F-FF-44-8E-9F-D0-66-94-9D-B3-4B** 一样返回..但是我需要 GUID 格式的输出,我该如何实现?

最佳答案

如何使用 Guid constructor which takes a byte array

Guid guid = new Guid(binaryData);

(如果需要,您可以使用 Guid.ToString() 以文本形式获取它。)

关于c# - 将 byte[] 或对象转换为 GUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10862171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com