在VS中运行时如何看到一个C#控制台程序的输出? [英] How to see output of a C# console program when running in VS?

查看:965
本文介绍了在VS中运行时如何看到一个C#控制台程序的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚写了一个名为helloworld的聪明程序。这是一个C#/。NET 4.5控制台应用程序。深处在扭曲的嵌套迷宫的逻辑中有使用Console.WriteLine()。



当我在命令行运行它时,它运行,我看到输出。



现在我在Visual Studio中,调整源代码(Hi 比Hello更有效),并通过点击F5进行测试。发生什么是控制台窗口弹出并立即消失。我不知道什么程序打印。我如何看到输出?



我不想修改我的源。搜索解决方案后,我找到一些人说,使用Console.ReadKey() - 但然后它会吸引在命令行中使用该程序。没有真正的理由,当程序已经完成了其工作,用户应该有点击键。即使我这样做,有一个问题,输出消失时,控制台窗口关闭点击之后。



我不想使用Debug.WriteLine )它写入到VS中的输出窗口,但不写入普通输出供最终用户查看。



我发现了ctrl-F5,程序,好像它有一个最终的Console.ReadKey()行,但仍有问题,当我点击任何键,所有的输出消失与窗口。三分钟后,我想哦,等等,打印'你好'还是'Helo'?没有办法检查。



似乎Visual Studio IDE应该以某种方式捕获一个新构建的程序写入其stdout或Microsoft的等同物,并显示在其输出面板,或一些面板,供以后审查。也许它做到了这一点,我还不知道它的伎俩吗?似乎这将是数百万C#开发人员的共同愿望。

解决方案

一些选项是:
1. wrap #if关于Console.ReadKey()的调试
2.直接从打开的终端运行
3.创建一个测试项目 - 但是你需要使用Console.ReadKey()来停止它。 p>

I just wrote a clever program called helloworld. It's a C#/.NET 4.5 console app. Deep within the twisted nested mazes of logic there's use of Console.WriteLine().

When I'm running this at a command line, it runs and I see the output. I can do other commands and mess around a bit, and later scroll up to see the output again.

Now I'm in Visual Studio, tweaking the source ("Hi" is more efficient than "Hello") and testing by tapping F5. What happens is a console window pops up and immediately vanishes. I have no idea what the program printed. How can I see the output?

I don't want to modify my source at all. After searching for solutions, I find some who say to use Console.ReadKey() - but then it would suck to be using the program at the command line. There's no real reason the user should have to tap a key when the program has already done its work. Even if i go with this, there's the problem of the output disappearing when the console window closes after a key tap.

I don't want to use Debug.WriteLine() which does write to the output window in VS, but doesn't write ordinary output for the end user to see.

I have discovered ctrl-F5, which runs the program as if it had a final Console.ReadKey() line, but there's still the problem of when I tap any key, all the output vanishes along with the window. Three minutes later, I'm thinking "Oh wait, did it print 'Hello' or 'Helo'?" No way to check.

Seems like the Visual Studio IDE should somehow capture all that a freshly built program writes to its stdout or the Microsoft equivalent thereof, and show it in its "Output" panel, or some panel, for later scrutiny. Maybe it does do this, and I don't yet know the trick to it? Seems like this would be a common desire among millions of C# developers.

解决方案

Some options are: 1. wrap #if DEBUG around Console.ReadKey() 2. run directly from an open terminal 3. create a Test project - but again you'll need Console.ReadKey() to stop it closing.

这篇关于在VS中运行时如何看到一个C#控制台程序的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆