I have to read a varbinary
column from SQL Server, and send it to a json.
I tried some test conversions byte[]
/string
and vice-versa, but I cannot understand what is wrong.
For example:
string s = System.Text.Encoding.Unicode.GetString((byte[])value);
byte[] ba = Encoding.Unicode.GetBytes(s);
bool f = ba.SequenceEqual((byte[])value); //false??? why??
as @Jon Skeet suggests:
string s = Convert.ToBase64String((byte[])value);
byte[] ba = Convert.FromBase64String(s);
bool f = ba.SequenceEqual((byte[])value); //true!!