returning a memoryStream as a string
Posted
by WeNeedAnswers
on Stack Overflow
See other posts from Stack Overflow
or by WeNeedAnswers
Published on 2010-03-26T11:35:39Z
Indexed on
2010/03/26
11:43 UTC
Read the original article
Hit count: 329
c#
What is wrong with this statement?
return new ASCIIEncoding().GetString(memoryStream.ToArray());
I know about the Dispose pattern, have checked out the underlying memoryStream and seen that there is nothing really happening in the dispose. So why shouldn't I allow one of my developers to do this.
The aim is to make the code succinct and not create references that are not required, Hopefully getting the Garbage Collector to kick in soon as.
Its just niggling me, I feel that the memoryStream lets the party down, when compared to what the other streams do and why they implement the IDispose.
Can someone please give me a good reason not to allow the code above. I got a gut feeing about the code not being right but need some back up. :)
© Stack Overflow or respective owner