14

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?

1
  • 'UTF8Encoding.UTF8' is not what you would usually use - you would either use Encoding.UTF8 to get the 'normal' UTF8 encoding (which has BOM on) or do 'new UTFEncoding(..)' to ctor your own. Commented Nov 2, 2010 at 5:27

3 Answers 3

37

You can write:

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

Silverlight 3 and 4 only support that override.

Sign up to request clarification or add additional context in comments.

Comments

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

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

Comments

2

You May use Inicode encoding also,

   String text=(new UnicodeEncoding()).GetString(barray, 0, barry.Length)

By this way you are able to get as string from byte[],

vice versa by

   Byte[] myarray=(new UnicodeEncoding()).getBytes(Stringexpressin);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.