C# - Convert byte[] to String in Windows 7 Phone
Hi I am trying to get device id of windows 7 phone using following code
byte[] result = null;
String id = null;
object uniqueId;
if (DeviceExtendedPr开发者_运维知识库operties.TryGetValue("DeviceUniqueId", out uniqueId))
result = (byte[])uniqueId;
Problem is that I need this result in String. Can anyone tell me how to do this? Best Regards
string myString = Convert.ToBase64String(result);
This function is available on the windows phone 7 platform
http://msdn.microsoft.com/en-us/library/dhx0d524(VS.95).aspx
And if you need the byte array again, just ask for it like this.
byte[] byteArray = Convert.FromBase64String(myString);
edit: Curt provided the correct way to convert back to a byte array
System.Text.Encoding.UTF8.GetString(myBytes, 0, myBytes.Length);
I haven't checked but I suppose this method is available on Windows Phone.
精彩评论