I often run into the problem that I have one stream full of data and want to write everything of it into another stream.
All code-examples out there use a buffer in form of a byte-array.
Is there a more elegant way to this?
If not, what’s the ideal size of the buffer. Which factors make up this value?
Regarding the ideal buffer size:
‘When using the Read method, it is more efficient to use a buffer that is the same size as the internal buffer of the stream, where the internal buffer is set to your desired block size, and to always read less than the block size. If the size of the internal buffer was unspecified when the stream was constructed, its default size is 4 kilobytes (4096 bytes).’
Any stream-reading process will use Read(char buffer[], int index, count), which is the method this quote refers to.
http://msdn.microsoft.com/en-us/library/9kstw824.aspx (Under ‘Remarks’).