Tip It might be better for this program to omit the using resource acquisition statement.
Detail The StreamWriter could be disposed of when the program exits automatically. This approach would reduce the code complexity.
static void Main()
using (StreamWriter writer = new StreamWriter("C:\\out.txt"))
static void Act()
Console.WriteLine("This is Console.WriteLine");
Console.WriteLine("Thanks for playing!");
}This is Console.WriteLine
Thanks for playing!
TextWriter. The Console.SetOut method receives an object of type TextWriter. The StreamWriter can be passed to Console.SetOut and it is implicitly cast to the TextWriter type.
Tip StreamWriter is more useful for writing text to files. TextWriter is mostly needed for interoperability.