String to Byte Array And Byte Array to String.

Here is two methods for string to Byte[]

Method 1
----------
public static byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}

Method 2
----------
byte[] byteArray = Encoding.UTF8.GetBytes(stringValue);

Byte[] to String
----------------

byte [] dBytes = ...
string str;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
str = enc.GetString(dBytes);

...S.VinothkumaR.

No comments: