This just another one of thoise dumb little snippets that I always forget and is a bit of a bugger to find...so, if you for some reason (e.g., compression / encryption) need all of the contents of a file to be held in a byte array, here's the simplest way I've found to do it:
byte[] inArr; using(Stream s=File.Open("myfile.dat",FileMode.Open)) { inArr = new byte[s.Length]; s.Read(inArr,0,inArr.Length); }
© 2025 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.