如何将 byte[100] 转换为 guid
我收到的服务响应是 byte[100]
我如何将其转换为 guid?
byte[] response = wc.UploadValues(url, "POST", nvc);
string Guid = new Guid(response).ToString();
Response.Write(Guid);
I am receiving a service response which is byte[100]
how can i convert it to a guid ?
byte[] response = wc.UploadValues(url, "POST", nvc);
string Guid = new Guid(response).ToString();
Response.Write(Guid);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个Guid构造函数,它允许您从16位初始化Guid -元素字节数组。因此,您必须首先将 100 个元素数组中的 16 个元素提取到一个新数组中,然后初始化 Guid。从 100 个元素的数组中提取哪 16 个元素当然取决于具体情况。
现在我怀疑这里发生的情况是服务器在响应中将 Guid 作为字符串发送。因此,您所要做的就是在转换后解析它使用正确的编码将服务器的响应转换为字符串:
There is a Guid constructor which allows you to initialize a Guid from a 16-element byte array. So you will have to first extract the 16 elements from your 100 elements array into a new one and then initialize the Guid. Which 16 elements to extract from your 100 elements array would of course depend.
Now I suspect that what happens here is that the server sends the Guid as a string in the response. So all you have to do is parse it after converting the response from the server into a string using the proper encoding:
我不完全理解您的代码片段,但 Guid 具有 new (byte[ ]) 和 ToByteArray 方法将 Guid 与字节数组相互转换 - 这应该可以解决问题
I don't fully understand your code snippet, but Guid has overloads for new (byte[]) and a ToByteArray Method to transform Guids from and into Byte-Arrays - that should do the trick