Q:

How do I convert a byte array to a string

I have a byte array which I got back from a FileStream.Read and I would like to turn that into a string. I'm not 100% sure of the encoding - it's just a file i saved to disk - how do I do the conversion? Is there a .NET class that reads the byte order mark and can figure out the encoding for me?

A:

See how-to-guess-the-encoding-of-a-file-with-no-bom-in-net.
Since strings are Unicode, you must specify an encoding on conversion. Text streams (even ReadAllText() ) have an active encoding inside, usually some sensible default.

A:

If File.ReadAllText will read the file correctly, then you have a couple of options.
Instead of calling BeginRead, you could just call File.ReadAllText asynchronously:
    delegate string AsyncMethodCaller(string fname);

    static void Main(string[] args)
    {
        string InputFilename = "testo.txt";
        AsyncMethodCaller caller = File.ReadAllText;
        IAsyncResult rslt = caller.BeginInvoke(InputFilename, null, null);

        // do other work ...

        string fileContents = caller.EndInvoke(rslt);
    }

Or you can create a MemoryStream from the byte array, and then use a StreamReader on that.

