开发者

Convert a Byte Array to String in Silverlight?

开发者 https://www.devze.com 2023-01-22 09:37 出处:网络
I\'m trying to convert a byte array to a string in Silverlight, but I get the following compilation error:

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(my开发者_开发知识库ByteArray);

How else can I achieve this?


You can write:

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

Silverlight 3 and 4 only support that override.


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

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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号