Console.Error Property
.NET Framework 4
Gets the standard error output stream.
Assembly: mscorlib (in mscorlib.dll)
Property Value
Type: System.IO.TextWriterA TextWriter that represents the standard error output stream.
This property is set to the standard error stream by default. This property can be set to another stream with the SetError method.
The following code example illustrates the use of the Error property.
public class ExpandTabs { private const int tabSize = 4; private const string usageText = "Usage: EXPANDTABSEX inputfile.txt outputfile.txt"; public static int Main(string[] args) { StreamWriter writer = null; TextWriter standardOutput = Console.Out; if (args.Length < 2) { Console.WriteLine(usageText); return 1; } try { writer = new StreamWriter(args[1]); Console.SetOut(writer); Console.SetIn(new StreamReader(args[0])); } catch(IOException e) { TextWriter errorWriter = Console.Error; errorWriter.WriteLine(e.Message); errorWriter.WriteLine(usageText); return 1; } int i; while ((i = Console.Read()) != -1) { char c = (char)i; if (c == '\t') Console.Write(("").PadRight(tabSize, ' ')); else Console.Write(c); } writer.Close(); // Recover the standard output stream so that a // completion message can be displayed. Console.SetOut(standardOutput); Console.WriteLine("EXPANDTABSEX has completed the processing of {0}.", args[0]); return 0; } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
