Why does Console.Out.WriteLine exist?

前端 未结 2 2022
温柔的废话
温柔的废话 2021-02-06 23:21

Actually the question should be why does Console.WriteLine exist just to be a wrapper for Console.Out.WriteLine

I found this little method usin

2条回答
  •  一个人的身影
    2021-02-06 23:52

    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.

提交回复
热议问题