Write and read string with StringReader and StringWriter in CSharp
Description
The following code shows how to write and read string with StringReader and StringWriter.
Example
// www .ja v a 2s.com
using System;
using System.IO;
class MainClass {
public static void Main() {
StringWriter strwtr = new StringWriter();
for(int i=0; i < 10; i++)
strwtr.WriteLine("This is i: " + i);
StringReader strrdr = new StringReader(strwtr.ToString());
string str = strrdr.ReadLine();
while(str != null) {
str = strrdr.ReadLine();
Console.WriteLine(str);
}
}
}
The code above generates the following result.