using System.IO; StringWriter writer = new StringWriter(); writer.WriteLine("Hello, world!"); writer.Flush(); string result = writer.ToString(); Console.WriteLine(result);In this example, we create a new StringWriter object and write a line of text to it. We then flush the writer to ensure that all of the characters are written to the string, and retrieve the resulting string using the ToString method. Finally, we print the string to the console. Package library: The System.IO namespace is part of the .NET Framework Class Library, so no external package library is required.