Streams - .NET Framework

Reading a String into a Memory Stream

var contents = "Hello world";
var ms = new MemoryStream(ASCIIEncoding.Default.GetBytes(contents));

Reading a File into a Memory Stream

var fi = new FileInfo(sourceFile);
using (var fs = fi.OpenRead())
{
    using (var ms = new MemoryStream())
    {
        ms.SetLength(fs.Length);
        fs.Read(ms.GetBuffer(), 0, (int)fs.Length);
        ms.Flush();
        fs.Close();

        // Do something here with the memory stream
    }
}