Lucas Lucas - 1 year ago 85
C# Question

Why does Console.Out.WriteLine exist?

Actually the question should be why does

exist just to be a wrapper for

I found this little method using intellisense, then opened .NET reflector and 'decompiled' the code for the
method and found this:

public static void WriteLine(string value)

So why is
implemented this way? Is it totally just a shortcut or is there another reason?

Answer Source

Console.WriteLine is a static method. Console.Out is a static object that can get passed as a parameter to any method that takes a TextWriter, and that method could call the non-static member method WriteLine.

An example where this would be useful is some sort of customizable logging routines, where you might want to send the output to stdout (Console.Out), stderr (Console.Error) or nowhere (System.IO.TextWriter.Null), or anything else based on some runtime condition.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download