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();

  }
}
    




















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version