using System; using System.IO; class Program { static void Main() { StringWriter strWriter = new StringWriter(); // Writing data to the StringWriter strWriter.Write("Hello, "); strWriter.WriteLine("World!"); strWriter.WriteLine("How are you?"); // Retrieving the content of the StringWriter string stringContent = strWriter.ToString(); Console.WriteLine(stringContent); } }
Hello, World! How are you?
using System; using System.IO; class Program { static void Main() { StringWriter strWriter = new StringWriter(); // Writing formatted data to the StringWriter strWriter.WriteLine("My name is {0}, I am {1} years old", "John", 30); // Retrieving the content of the StringWriter string stringContent = strWriter.ToString(); Console.WriteLine(stringContent); } }
My name is John, I am 30 years oldIn both the code examples, the package library is "System.IO".