how to convert byte[100] to guid

一笑奈何 提交于 2020-01-06 07:23:11

问题


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

回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/7298672/how-to-convert-byte100-to-guid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!