Example of stringreader and stringwriter

 
 
// Demonstrate StringReader and StringWriter 
 
using System; 
using System.IO; 
 
public class StrRdrDemo {   
  public static void Main() {   
    // Create a StringWriter 
    StringWriter strwtr = new StringWriter(); 
 
    // Write to StringWriter. 
    for(int i=0; i < 10; i++) 
       strwtr.WriteLine("This is i: " + i); 
 
    // Create a StringReader 
 
    StringReader strrdr = new StringReader(strwtr.ToString()); 
 
    // Now, read from StringReader. 
    string str = strrdr.ReadLine(); 
    while(str != null) { 
      str = strrdr.ReadLine(); 
      Console.WriteLine(str); 
    }  
 
  }  
}
Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

 

 
eXTReMe Tracker