<t>It really depends on whether or not you can trust s.Length. For many streams, you just don't know how much data there will be. In such cases - and before .NET 4 - I'd use code like this:<br/>
<br/>
public static byte[] ReadFully(Stream input)<br/>
{<br/>
byte[] buffer = new byte[16*1024];<br/>
using (MemoryStream ms = new MemoryStream())<br/>
{<br/>
int read;<br/>
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)<br/>
{<br/>
ms.Write(buffer, 0, read);<br/>
}<br/>
return ms.ToArray();<br/>
}<br/>
}<br/>
<br/>
```<br/>
<br/>
With .NET 4 and above, I'd use [`Stream.CopyTo`](https://msdn.microsoft.com/en-us/library/system.io.stream.copyto), which is basically equivalent to the loop in my code - create the `MemoryStream`, call `stream.CopyTo(ms)` and then return `ms.ToArray()`. Job done.<br/>
<br/>
I should perhaps explain why my answer is longer than the others. [`Stream.Read`](http://msdn.microsoft.com/en-us/library/system.io.stream.read.aspx) doesn't guarantee that it will read everything it's asked for. If you're reading from a network stream, for example, it may read one packet's worth and then return, even if there will be more data soon. [`BinaryReader.Read`](http://msdn.microsoft.com/en-us/library/system.io.binaryreader.read.aspx) will keep going until the end of the stream or your specified size, but you still have to know the size to start with.<br/>
<br/>
The above method will keep reading (and copying into a `MemoryStream`) until it runs out of data. It then asks the `MemoryStream` to return a copy of the data in an array. If you know the size to start with - or *think* you know the size, without being sure - you can construct the `MemoryStream` to be that size to start with. Likewise you can put a check at the end, and if the length of the stream is the same size as the buffer (returned by [`MemoryStream.GetBuffer`](http://msdn.microsoft.com/en-us/library/system.io.memorystream.getbuffer.aspx)) then you can just return the buffer. So the above code isn't quite optimised, but will at le<br/>
<br/>
*(Réponse tronquée)*</t>