using System.IO; class Program { static void Main(string[] args) { var sw = new StringWriter(); sw.Write("Hello World!"); Console.WriteLine(sw.ToString()); } }
using System.IO; class Program { static void Main(string[] args) { var sw = new StringWriter(); var writer = new StreamWriter(sw); writer.Write("Hello World!"); Console.WriteLine(sw.ToString()); } }In this example, we first create an instance of the StringWriter class. We then create a StreamWriter and pass our StringWriter as the first parameter. We then write the text "Hello World!" to the StreamWriter and retrieve the contents of the StringWriter using the `ToString()` method. Package Library The System.IO namespace is a part of the .NET Standard Library, which provides a set of common APIs for all .NET implementations. Therefore, it does not require any additional package library to be installed as it is a part of the core .NET libraries.