C # - convert byte [] to string in Windows 7 Phone

Hi I'm trying to get the device id on a Windows 7 phone using the following code

 byte[] result = null;
 String id = null;
 object uniqueId;
 if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out uniqueId))
     result = (byte[])uniqueId;

The problem is that I need this result in String. Can someone tell me how to do this? Regards

+3
source share
2 answers
string myString = Convert.ToBase64String(result);

This feature is available on the Windows Phone 7 platform.

http://msdn.microsoft.com/en-us/library/dhx0d524(VS.95).aspx

And if you need an array of bytes again, just ask it like this.

byte[] byteArray = Convert.FromBase64String(myString);

edit: Curt provided the correct way to convert back to byte array

+9
source
System.Text.Encoding.UTF8.GetString(myBytes, 0, myBytes.Length);

I have not tested, but I suppose this method is available on Windows Phone.

+2
source

Source: https://habr.com/ru/post/1772131/


All Articles