C#: Converting byte array to string and printing out to console

c

public void parse_table(BinaryReader inFile)
{
    byte[] idstring = inFile.ReadBytes(6);
    Console.WriteLine(Convert.ToString(idstring));
}

It is a simple snippet: read the first 6 bytes of the file and convert that to a string.

However the console shows System.Byte[].

Maybe I'm using the wrong class for conversion. What should I be using? It will eventually be parsing filenames encoded in UTF-8, and I'm planning to use the same method to read all filenames.

Best Answer

It's actually:

    Console.WriteLine(Encoding.Default.GetString(value));

or for UTF-8 specifically:

    Console.WriteLine(Encoding.UTF8.GetString(value));