如何将字节[100]转换为GUID[英] how to convert byte[100] to guid

本文是小编为大家收集整理的关于如何将字节[100]转换为GUID的处理方法,想解了如何将字节[100]转换为GUID的问题怎么解决?如何将字节[100]转换为GUID问题的解决办法?如何将字节[100]转换为GUID问题的解决方案?那么可以参考本文帮助大家快速定位并解决问题,译文如有不准确的地方,大家可以切到English参考源文内容。

问题描述

我正在收到一个服务响应,该响应是byte[100]如何将其转换为GUID?

byte[] response = wc.UploadValues(url, "POST", nvc);
string Guid = new Guid(response).ToString();
Response.Write(Guid);

推荐答案

有一个 guid constructor 初始化16个元素字节阵列的GUID.因此,您必须首先从100个元素数组中提取16个元素,然后初始化GUID.当然,从100个元素阵列中提取的16个元素当然取决于.

现在,我怀疑这里发生的事情是服务器将GUID作为响应中的字符串发送.因此,您要做的就是 artse it 使用正确编码的服务器对字符串的响应:

byte[] response = wc.UploadValues(url, "POST", nvc);
var guid = Guid.Parse(Encoding.UTF8.GetString(response));

其他推荐答案

我不完全理解您的代码段,但是GUID的过载 new(byte [])和a 方法要将GUID从字节阵列转换为字节阵列 - 应该做技巧

本文地址:https://www.itbaoku.cn/post/1980245.html

问题描述

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);

推荐答案

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:

byte[] response = wc.UploadValues(url, "POST", nvc);
var guid = Guid.Parse(Encoding.UTF8.GetString(response));

其他推荐答案

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

查看更多