Reading binary data in C#

Matt Berther bio photo By Matt Berther Comment

If you're reading binary data from streams using syntax similar to the following, you'll need to make sure to read this article. This code is not at all guaranteed to work.

byte[] buffer = null;
using (Stream strm = File.OpenRead(filename))
    buffer = new byte[strm.Length];
    fs.Read(buffer, 0, buffer.Length);