Use StringWriter to write string
using System;
using System.IO;
using System.Text;
class StringReadWriteApp {
static void Main(string[] args) {
StringWriter w = new StringWriter();
w.WriteLine("Sing a song of {0} pence", 6);
string s = "A pocket full of rye";
w.Write(s);
w.Write(w.NewLine);
w.Write(String.Format(4 + " and " + 20 + " blackbirds"));
w.Write(new StringBuilder(" baked in a pie"));
w.WriteLine();
w.Close();
Console.WriteLine(w);
}
}
Related examples in the same category