using System; using System.IO; class Program { static void Main(string[] args) { StringWriter writer = new StringWriter(); writer.Write("Hello, "); writer.Write("World!"); writer.Flush(); Console.WriteLine(writer.ToString()); // Output: "Hello, World!" } }
using System; using System.IO; class Program { static void Main(string[] args) { StringWriter writer = new StringWriter(); writer.Write("Hello, "); // Do not flush, which leaves an incomplete string Console.WriteLine(writer.ToString()); // Output: "Hello, " } }In this example, we create a StringWriter object, write the string "Hello, " to it, but do not call the Flush method. This leaves the internal buffer of the StringWriter with an incomplete string, as we have not yet written the "World!" string. When we try to print the contents of the StringWriter to the console, it outputs only "Hello, ", without the "World!" string. Package library: The System.IO namespace is part of the .NET Framework Class Library, which is included in the .NET Framework package.