- env
Visual Studio 2019 Community
.net framework 4.7.2
- 解决
使用了其他语句,将想要查看的信息打印在Output窗口。
4点:
- 输出语句必须使用 System.Diagnostics.Debug.WriteLine("22222");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcMovie.Controllers
{
public class WyjController : Controller
{
public string Index()
{
Console.WriteLine("11111");
System.Diagnostics.Debug.WriteLine("22222 " + DateTime.Now); // 会输出到 Output
return "访问成功 " + DateTime.Now;
}
}
}
- 必须打开Output窗口 Ctrl+Alt+O
- 必须是调试而非运行,否则output中不会输出想要输出的信息。F5
| 功能本质 | 快捷键 | 菜单名(中文) | 菜单名(英文) |
|---|---|---|---|
| 调试(Debug) | F5 | 开始调试 | Start Debugging |
| 运行(Run) | Ctrl+F5 | 开始执行(不调试) | Start Without Debugging |
- 切换输出窗口显示的输出来源为调试/Debug
访问规则: WyjController中的Index方法的访问path: /Wyj/Index 或 /Wyj/
可以看到使用System.Diagnostics.Debug.WriteLine()输出的信息被打印。
测试成功。
打印变量是最原始最基本的Debug方案。。
其实也可以通过Debug操作去调试/观察程序的运行细节。
-
api
- Console.WriteLine Method (System) | Microsoft Docs
- Debug.WriteLine Method (System.Diagnostics) | Microsoft Docs



