What is the prefered method for creating a byte array from an input stream?
Here is my current solution with .NET 3.5.
Stream s; byte[] b; using (
You can use this extension method.
public static class StreamExtensions { public static byte[] ToByteArray(this Stream stream) { var bytes = new List(); int b; while ((b = stream.ReadByte()) != -1) bytes.Add((byte)b); return bytes.ToArray(); } }