Creating a Byte Array from a Stream in C#

The method below 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. For many streams, you just don’t know how much data there will be, so the code should be like this,

See this article for more info.