Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a Byte Array to String in Silverlight?

Tags:

c#

silverlight

I'm trying to convert a byte array to a string in Silverlight, but I get the following compilation error:

'System.Text.Encoding.GetString(byte[])' is inaccessible due to its protection level

This is the method that I'm using:

string text = UTF8Encoding.UTF8.GetString(myByteArray);

How else can I achieve this?

like image 469
JP Richardson Avatar asked Oct 29 '10 20:10

JP Richardson


2 Answers

You can write:

string text = UTF8Encoding.UTF8.GetString(yourByteArray, 0, yourByteArray.Length);

Silverlight 3 and 4 only support that override.

like image 175
Frédéric Hamidi Avatar answered Nov 15 '22 14:11

Frédéric Hamidi


string text = Encoding.UTF8.GetString(myByteArray,0,myByteArray.Length);

Works in SL4, don't know about anything earlier.

like image 34
Stephan Avatar answered Nov 15 '22 15:11

Stephan