Write to Console.Out and Console.Error : Console Output « Development « C# / CSharp Tutorial






using System; 
 
class MainClass { 
  public static void Main() { 
    int a=10, b=0; 
    int result; 
 
    Console.Out.WriteLine("This will generate an exception."); 
    try { 
      result = a / b; // generate an exception 
    } catch(DivideByZeroException exc) { 
      Console.Error.WriteLine(exc.Message); 
    } 
  } 
}
This will generate an exception.
Attempted to divide by zero.








14.3.Console Output
14.3.1.Console I/O
14.3.2.WriteLine
14.3.3.Write without new line
14.3.4.Substituting Values
14.3.5.Substituting Values twice
14.3.6.Write to Console.Out and Console.Error
14.3.7.Output an int to console
14.3.8.Concatenate string in Console.WriteLine
14.3.9.Format the same argument three different ways
14.3.10.Display arguments in non-sequential order
14.3.11.Variable index
14.3.12.Variable index: reference a variable more than once
14.3.13.Escape Characters: \\
14.3.14.Adds a total of 4 blank lines (then beep again!)
14.3.15.Displaying a Triangle Using a Verbatim String Literal
14.3.16.Use OpenStandardOutput method.