我正在编写一个简单的C# 程序,其中有一些输出( Console.WriteLine("...");
) 。 问题是,每次运行它时,我都无法在输出窗口中看到程序的输出。
"程序输出"标记已经被选中,我已经将所有输出重定向到中间窗口,但没有使用。
如何启用程序的输出?
我不认为问题在于我的代码。 我尝试运行一个简单的程序,只输出一个字符串和 readline"ala hello",我仍然无法看到任何输出。 问题是我在寻找错误的位置或者 Visual Studio 运行结果。
debug.write
方法也不工作。
感谢所有有用的评论=
发布于 2017-12-28 04:02:36
可以使用System.Diagnostics.Debug.Write
方法将消息写入输出窗口。
发布于 2017-12-28 05:03:26
下面是一些要检查的东西:
console.Write/WriteLine
,你的应用程序必须是控制台应用程序。 ( right-click项目在解决方案资源管理器中,选择属性,看看"输出类型"组合应用程序中的选项卡--应该"控制台应用程序"(注意,如果你真的需要一个 Windows 应用程序或类库,不改变这个控制台应用程序只是让 Console.WriteLine
)。System.Diagnostics.Debug.WriteLine
写入输出窗口( 在 vs 显示输出窗口,必须视图 | 输出) 注意这些写入只在定义了调试条件的构建中发生( 默认情况下,调试生成定义了这个,并且释放生成没有)System.Diagnostics.Trace.Writeline
如果你希望能够写的可配置"侦听器"non-debug构建。 ( 默认情况下,这将写入 Visual Studio 中的输出窗口,就像 Debug.Writeline
)发布于 2017-12-28 06:04:57
在你的程序末尾添加一个 Console.Read();
。 它将保持应用程序不关闭,你可以看到它是以。
这是一个控制台应用程序,我刚刚在处理后停止,但在退出之前停止:
复制代码
class Program
{
static void Main(string[] args)
{
DummyObjectList dol = new DummyObjectList(2);
dol.Add(new DummyObject("test1", (Decimal)25.36));
dol.Add(new DummyObject("test2", (Decimal)0.698));
XmlSerializer dolxs = new XmlSerializer(typeof(DummyObjectList));
dolxs.Serialize(Console.Out, dol);
Console.WriteLine(string.Empty);
Console.WriteLine(string.Empty);
List<DummyObject> dolist = new List<DummyObject>(2);
dolist.Add(new DummyObject("test1", (Decimal)25.36));
dolist.Add(new DummyObject("test2", (Decimal)0.698));
XmlSerializer dolistxs = new XmlSerializer(typeof(List<DummyObject>));
dolistxs.Serialize(Console.Out, dolist);
Console.Read();//<--- Right here
}
}
或者,你可以在最后一行添加一个断点。
https://stackoverflow.com/questions/-100001316
复制相似问题