MemoryStream GetBuffer Vs ToArray

If you need to read the data from MemoryStream, always use ToArray() method instead of GetBuffer() method.

string Output = Encoding.UTF8.GetString(mstream.ToArray());

MemoryStream.GetBuffer() method returns the entire allocated buffer (even the unused buffer) and with ” padding for the unused buffer space.

Enjoy!!!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.