varbinary string to byte array c# code example
Example 1: c# string to byte array
string author = "Mahesh Chand";
byte[] bytes = Encoding.ASCII.GetBytes(author);
string str = Encoding.ASCII.GetString(bytes);
Example 2: string from byte array c#
var str = System.Text.Encoding.Default.GetString(result);
Example 3: c# string to byte[]
using System.Text;
public static byte[] encode(string stringToEncode)
{
UTF8Encoding utf8 = new UtF8Encoding();
byte[] bytename = new byte[1024];
bytename = utf8.GetBytes(stringToEncode);
return bytename;
}