如何隐藏一个控制台应用程序的输出(而不是窗口)? [英] How to hide output (not the window) in a console application?
问题描述
好吧,让我说清楚一次。我有许多类的控制台应用程序,在每类有至少一个Console.WriteLine(文本)线。我定义的一些参数,运行应用程序时,它的输出正是我在课堂上这样写道。在那里,我想定义的参数,当我有这样的说法运行应用程序时,会出现在控制台屏幕上没有输出,但依然会出现在控制台窗口。这个论点也许像-s。那么,有什么办法可以做到这一点无需在每个班级使用如果条件,并传递一个参数,通过类? 。非常感谢
Well, let me make it clear again. I have a console application with many classes, in each class there is at least one Console.WriteLine("text") line. I defined some arguments that when running the application, it output exactly what I wrote in classes. There, I want to define an argument that when I run the app with this argument, there will be no output on the console screen but the console window still appears. The argument maybe something like "-s". So is there any way I can do this without using the "if" condition in each class and passing an parameter through classes? Many thanks.
P / S:我已经搜查直通互联网,并发现了与此相关的一些文章,但大部分的答案是隐藏控制台窗口。我认为这个问题应该是什么样的人的意思。
P/S: I've searched thru the internet and found out some articles related to this, but most of the answers were to hide the console window. I think this question should be what the others meant.
推荐答案
使用Console.SetOut(的http://msdn.microsoft.com/en-us/library/system.console.setout.aspx )和传递一个空的文字作家。在 -s
的想法执行 Console.SetOut(新的StreamWriter())
。
Use Console.SetOut (http://msdn.microsoft.com/en-us/library/system.console.setout.aspx) and pass in a "null" text writer. The idea on -s
perform a Console.SetOut(new StreamWriter())
.
的 Console.SetOut
方法的例子将帮助您开始。
The example for the Console.SetOut
method will help you get started.
此外,您可以轻松地添加使用此方法登录。
In addition, you can easily add logging using this method.
这篇关于如何隐藏一个控制台应用程序的输出(而不是窗口)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!