This question already has an answer here:
Is there an easy way to convert a byte array to a string so the following unit test passes? I can't find an encoding that works for all values.
[TestMethod]
public void TestBytToString()
{
byte[] bytArray = new byte[256];
for (int i = 0; i < bytArray.Length; i++)
{
bytArray[i] = (byte)i;
}
string x = System.Text.Encoding.Default.GetString(bytArray);
for (int i = 0; i < x.Length; i++)
{
int y = (int)x[i];
Assert.AreEqual(i, y);
}
}
Array.ConvertAll
should work for creating achar[]
, which you can pass to a string constructor. – Ben Voigt Jul 24 '13 at 20:46string x = new string(bytArray.Select(Convert.ToChar).ToArray());
Credit goes to @Ricky – Mechanical Object Jul 24 '13 at 21:56