C# Console SetOut
Description
Console SetOut
sets the Out property to the specified
TextWriter object.
Syntax
Console.SetOut
has the following syntax.
[HostProtectionAttribute(SecurityAction.LinkDemand, UI = true)]
public static void SetOut(
TextWriter newOut
)
Parameters
Console.SetOut
has the following parameters.
newOut
- A stream that is the new standard output.
Returns
Console.SetOut
method returns
Example
//from w w w. j a va 2 s .co m
using System;
using System.IO;
public class MainClass{
public static void Main(String[] argv){
FileStream fs = new FileStream("Test.txt", FileMode.Create);
TextWriter tmp = Console.Out;
StreamWriter sw = new StreamWriter(fs);
Console.SetOut(sw);
Console.WriteLine("Hello file");
Console.SetOut(tmp);
Console.WriteLine("Hello World");
sw.Close();
}
}