wolfgang ziegler


„make stuff and blog about it“

Read String from Stream in C#

July 19, 2011

A reoccurring task I identified during my .NET / C# programming career is to read string contents from a given stream object.

I have seen the weirdest approaches to this issue involving memory streams, byte arrays and all kinds of conversion an copy operations.

Acually it’s as simple as that:

Stream stream = ...
StreamReader reader = new StreamReader(stream);
string text = reader.ReadToEnd();