Debug 类
来源:互联网 发布:dhc瘦腿丸瘦腿原理知乎 编辑:程序博客网 时间:2024/06/05 14:16
原文链接:Debug 类
提供一组帮助调试代码的方法和属性。 此类不能被继承。
下面的示例使用 Debug 指示程序执行的开始和结束。 该示例还使用 Indent 和 Unindent 方法区分跟踪输出。
// Specify /d:DEBUG when compiling.using System;using System.Data;using System.Diagnostics;class Test{ static void Main() { Debug.Listeners.Add(new TextWriterTraceListener(Console.Out)); Debug.AutoFlush = true; Debug.Indent(); Debug.WriteLine("Entering Main"); Console.WriteLine("Hello World."); Debug.WriteLine("Exiting Main"); Debug.Unindent(); }}
第一个查看位置:
第二个查看位置:
使用目的:
要想调试查看程序中某个变量,可以给出弹出框查看;也可以用Debug类写到输出中查看。
原文链接:http://blog.csdn.net/aaaaatiger/article/details/5583301
Debug是输出到output窗口;Console是输出到控件台窗口;
而且Debug必须要在Debug情况下才有效,你按Ctrl+F5后会看到Console的输出,
按F5后也能看到Console的输出,还可以看到output中Debug的输出。
原文链接:http://blog.csdn.net/y13156556538/article/details/70153477
c#的Debug.WriteLine()和Trace.WriteLine()
1.区别:
//输出跟踪信息
Trace.WriteLine()
将有关跟踪的信息写入 Listeners 集合中的跟踪侦听器
在调试和release模式都输出!默认是写到输出窗口的,也可以指定写到指定文件,或系统日志中!
//输出调试信息
Debug.WriteLine()
将有关调试的信息写入Listeners集合中的跟踪侦听器 。
只有调试的时候才输出。
2.相同点
都是为了在一些不适合断点调试的情况下,向调试窗口输出一些调试信息,以便跟踪发现程序运行的问题。
你选择“视图”—>”输出”窗口,就可以看到输出的结果了;
class Program{ static void Main(string[] args) { //测试 MathTest(12, 0); MathTest(12, 2); } private static int MathTest(int x, int y) { if (y == 0) { System.Diagnostics.Trace.WriteLine("Trace->两个数相除时,分母不能为零。"); return -1; } x /= y; System.Diagnostics.Debug.WriteLine(string.Format("Debug->{0}/{1}={2}", x, y, x / y)); return x; }}
效果图:
- Debug类
- Debug 类
- 发现了Debug类
- android.os.Debug类
- DEBUG
- debug
- DEBUG
- debug
- debug
- debug
- DEBUG
- Debug
- Debug
- debug
- debug
- DEBUG
- debug
- debug
- 用web制作简历
- Python闭包简谈
- MATLAB图像处理基础知识3 mapminmax
- 浅谈PLC控制系统的可靠性
- "message":"Illegal base64 character a"
- Debug 类
- Spring基础学习笔记
- 数字组合
- js进度条插件之spin使用方式
- 机器学习中的必修数学(七)
- 网络爬虫抓包的使用
- 用matlab画散点图,并指定点与点之间的连线
- ofbiz学习——选择目录
- Apache整合tomcat分离静态资源与动态资源