Console.OpenStandardError Method in C# Last Updated : 06 May, 2019 Comments Improve Suggest changes Like Article Like Report This method is used to acquire a standard error stream. This method can be used to reacquire the standard error stream after it has been changed by the SetError method. Syntax: public static System.IO.Stream OpenStandardError (); Returns: This method returns the standard error stream. Example: The below code first checks for the string to be GeeksForGeeks and if not so then the program calls the SetError method to redirect error information to a file, calls the OpenStandardError method in the process of reacquiring the standard error stream, and indicates that error information was written to a file. The StreamWriter.AutoFlush property is set to true before reacquiring the error stream. This ensures that output will be sent to the console immediately rather than buffered. csharp // C# program to illustrate the // OpenStandardError() Method using System; using System.IO; namespace GeeksforGeeks { class GFG { // Main Method static void Main(string[] args) { Console.WriteLine("Please Write GeeksForGeeks"); string a; a = Console.ReadLine(); // checks for a string to be GeeksforGeeks if (!a.Equals("GeeksForGeeks")) { // Write error information to a file. Console.SetError(new StreamWriter(@".\Errorfile.txt")); Console.Error.WriteLine("The String is not GeeksForGeeks"); Console.Error.Close(); // Reacquire the standard error stream. var standardError = new StreamWriter(Console.OpenStandardError()); standardError.AutoFlush = true; Console.SetError(standardError); Console.Error.WriteLine("\nError information written"+ " to Errorfile.txt"); } } } } Executing on Cmd: Output File: Reference: https://docs.microsoft.com/en-us/dotnet/api/system.console.openstandarderror?view=netframework-4.8#System_Console_OpenStandardError Comment More infoAdvertise with us Next Article Console.OpenStandardError Method in C# piyush25pv Follow Improve Article Tags : C# CSharp-method CSharp-Console-Class Similar Reads Console.OpenStandardInput Method in C# Console.OpenStandardInput Method is used to get the standard input stream. There are two overloads of OpenStandardInput method available in C# which are listed below: OpenStandardInput() Method OpenStandardInput(int32) Method OpenStandardInput() Method It is used to get the standard input stream. Ma 2 min read Console.SetError() Method in C# The Console.SetError(TextWriter) Method sets the Error property of the specified StreamWriter i.e., it redirects the standard error stream to a file. As the console is set with this StreamWriter object, the WriteLine() method can be called to write the error into the file. Syntax: public static void 2 min read Console.Read() Method in C# Console.Read() Method is used to read the next character from the standard input stream. This method basically blocks its return when the user types some input characters. As soon as the user press ENTER key it terminates. Syntax: public static int Read (); Return Value: It returns the next characte 1 min read Console.ReadKey() Method in C# Console.ReadKey() Method makes the program wait for a key press and it prevents the screen until a key is pressed. In short, it obtains the next character or any key pressed by the user. The pressed key is displayed in the console window(if any input process will happen). There are two methods in th 5 min read Console.OpenStandardOutput() Method in C# with Examples Console.OpenStandardOutput Method is used to get the standard output stream. There are two overloads of OpenStandardOutput method available in C# which are listed below: OpenStandardOutput() Method OpenStandardOutput(int32) Method OpenStandardOutput() Method It is used to get the standard output str 2 min read Console.ReadLine() Method in C# This method is used to read the next line of characters from the standard input stream. It comes under the Console class(System Namespace). If the standard input device is the keyboard, the ReadLine method blocks until the user presses the Enter key. And if standard input is redirected to a file, th 2 min read Console.SetIn() Method in C# The Console.SetIn() method is used to set the In property of the specified StreamReader object i.e. it redirects the standard input from the console to the input file. Since the console is set with this StreamReader object, the ReadLine() method can be called to read the contents of the file, line b 2 min read Console.SetOut() Method in C# Console.SetOut(TextWriter) Method in C# is used to redirect the stream of standard output. With the help of this method, a user can specify a StreamWriter as the output object. The Console.SetOut method will receive an object of type TextWriter. The StreamWriter can be passed to Console.SetOut and i 2 min read Console.SetWindowPosition() Method in C# Console.SetWindowPosition(Int32, Int32) Method in C# is used to set the position of the console window relative to the screen buffer. Syntax: public static void SetWindowposition(int left, int top); Parameters: left: It is the column position of the upper left corner of the console window. top: It i 1 min read Console.Clear Method in C# This method is used to clear the console buffer and corresponding console window of display information. Syntax: public static void Clear (); Exceptions: This method throws IOException if an I/O error occurred. Below programs show the use of Console.Clear() method: Program 1: To display the contents 1 min read Like