I found this and I wonder why there is a memory allocation on the the variable in the loop (…. 0x20;). It looks like the variable is simply filled up with spaces. But why would one do this when we initialize the byte variable with the size ?
long fileByteLength = package.Properties.Length;
byte fileContent = new byte[fileByteLength];
for (int i = 0; i < fileByteLength; i++)
fileContent[i] = 0x20;
// Download the file aa a byteArray to the fileContent variable
The obvious answer is: because the programmer wanted to have it filled up with spaces. Initializing it with the length means you get a lot of 0 bytes. Why did the programmer want spaces? I have no idea. The whole thing is bad cargo-cult programming (meaning somebody did it because he saw somebody else doing it, without understanding how it works or what it does).
You should either use a stream or use the return value of that method. If your quality guideline is “good programming”, then that loop has to be deleted and replaced by either of the above solutions.
My preference would be the stream (could be a MemoryStream) so that you get rid of all that byte-counting and buffer shifting and return-value-checking. That is what the stream abstraction was made for.