If I use a buffer that is bigger than the count will the program only take the desired length from the buffer?
Yes, the count is the maximum number of bytes to be read in a call to Stream.Read
, or the exact number of bytes to be written in a call to Stream.Write
.
Note that Stream.Read
returns the actual number of bytes read, which may be less than requested, even if there may still be more data to read if you call Read
again. A common mistake is to ignore the value returned from Stream.Read
. There's no equivalent for Stream.Write
, as that always writes all the data you've said to write (or throws an exception if it can't do so).
See more on this question at Stackoverflow