这篇文章主要介绍了C#中的两种debug方法介绍,本文讲解了代码用 #if DEBUG 包裹、利用宏定义两种方法,需要的朋友可以参考下
 

第一种:需要把调试方法改成debug
代码用 #if DEBUG 包裹

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
 
namespace SplitPackage
{
  public static class EnvConfig
  {
    static EnvConfig()
    {
#if DEBUG
      ToolsPath = @"D:\workspace\shopstyle\tool";
#else
      ToolsPath = Environment.CurrentDirectory;
#endif
      int rootIdx = ToolsPath.LastIndexOf(@"\");
      if (rootIdx > 0)
      {
        RootPath = ToolsPath.Substring(0, rootIdx);
      }
    }
    public static string ToolsPath { get; private set; }
    public static string TmplateFile { get { return Path.Combine(ToolsPath, @"template\default.pm"); } }
    public static string RootPath { get; private set; }
    public static string ModulePath { get { return Path.Combine(RootPath, "module"); } }
    public static string ConfigPath { get { return Path.Combine(RootPath, "conf"); } }
 
  }
}

第二种:
利用宏定义

#define DEBUG// C#的宏定义必须出现在所有代码之前。当前我们只让DEBUG宏有效。
using System.Diagnostics;  //必须包含这个包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#define DEBUG
 
using System.Diagnostics;
 
namespace TestConsole
{
  class ToolKit
  {
    [ConditionalAttribute("LI")]       // Attribute名称的长记法
    [ConditionalAttribute("DEBUG")]
    public static void Method1() { Console.WriteLine("Created By Li, Buged.11"); }
 
    [ConditionalAttribute("LI")]
    [ConditionalAttribute("NOBUG")]
    public static void Method2() { Console.WriteLine("Created By Li, NoBug."); }
 
    [Conditional("ZHANG")]          // Attribute名称的短记法
    [Conditional("DEBUG")]
    public static void Method3() { Console.WriteLine("Created By Zhang, Buged.11"); }
 
    [Conditional("ZHANG")]
    [Conditional("NOBUG")]
    public static void Method4() { Console.WriteLine("Created By Zhang, NoBug."); }
  }
    static void Main(string[] args)
    {
      ToolKit.Method1();
      ToolKit.Method2();
      ToolKit.Method3();
      ToolKit.Method4();
    }
  }
}

C#中的两种debug方法的更多相关文章

  1. JS中的两种刷新方法以及区别和适用范围

    在项目中有一个人信息修改的页面,但是修改后显示的却是修改之前的内容,分析问题后发现查询语句写在了修改语句之前,有些某些需要又必须这么写,但是修改信息后先却显示之前的信息也太不科学了. 所以我就想用js ...

  2. 将文件放到Android模拟器的SD卡中的两种解决方法

    两种方式:一.窗口界面操作1.打开DDMS页面2.打开File Explorer页,如果没有,在Window --> Show View -->File Explorer3.一般就在mnt ...

  3. C# 的两种debug 方法

    第一种:需要把调试方法改成debug代码用 #if DEBUG 包裹 using System; using System.Collections.Generic; using System.Text ...

  4. Linux系统中存储设备的两种表示方法

    转:https://blog.csdn.net/holybin/article/details/38637381 一.对于IDE接口的硬盘的两种表示方法: 1.IDE接口硬盘,对于整块硬盘的两种表示方 ...

  5. 史上最全的CSS hack方式一览 jQuery 图片轮播的代码分离 JQuery中的动画 C#中Trim()、TrimStart()、TrimEnd()的用法 marquee 标签的使用详情 js鼠标事件 js添加遮罩层 页面上通过地址栏传值时出现乱码的两种解决方法 ref和out的区别在c#中 总结

    史上最全的CSS hack方式一览 2013年09月28日 15:57:08 阅读数:175473 做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我 ...

  6. HTML中label的两种使用方法

    如果您在 label 元素内点击文本,就会触发此控件.就是说,当用户选择该标签时,浏览器就会自动将焦点转到和标签相关的表单控件上. 有两种使用方法: 方法1: <label for=" ...

  7. 两种js方法发起微信支付:WeixinJSBridge,wx.chooseWXPay区别

    原文链接:https://www.2cto.com/weixin/201507/412752.html 1.为什么会有两种JS方法可以发起微信支付? 当你登陆微信公众号之后,左边有两个菜单栏,一个是微 ...

  8. keil结合st-link使用SWO的两种调试方法笔记

    通过strongerHuang的教程,实现了SWO的两种调试方法, 1.在keil调试的过程中,使用debug printf viewer打印信息, 2.在STM32 ST-LINK Utility中 ...

  9. angular2系列教程(十)两种启动方法、两个路由服务、引用类型和单例模式的妙用

    今天我们要讲的是ng2的路由系统. 例子

随机推荐

  1. 纯js将form表单的数据封装成json 以便于ajax发送

    使用方式: var json = form2Json("formId");//这里的参数是form表单的id值 form2json.js function form2Json(fo ...

  2. Jquery IE 缓存问题

    jQuery IE缓存问题 解决方法: 1.在AJAX请求的页面后加个随机函数,我们可以使用随机时间函数 在javascript发送的URL后加上t=Math.random() 例如这样:URL+”& ...

  3. Php使用sqlite

    php sqlite文档:http://php.net/manual/en/book.sqlite.php sql:http://www.php100.com/html/webkaifa/PHP/PH ...

  4. Python自然语言处理学习笔记(69)

    http://www.cnblogs.com/yuxc/archive/2012/02/09/2344474.html Chapter8    Analyzing Sentence Structure ...

  5. 【CF】259 Div.1 B Little Pony and Harmony Chest

    还蛮有趣的一道状态DP的题目. /* 435B */ #include <iostream> #include <string> #include <map> #i ...

  6. ImageSwitcher 右向左滑动的实现方式

    ImageSwitcher is;...is.setInAnimation(this, android.R.anim.slide_in_left);is.setOutAnimation(this, a ...

  7. Ajax长连接应用

    所谓的长连接,就是不断去发送请求,把请求阻塞在服务器端,每次超过请求时间就去重新发送请求,保持连接,随时获取服务器端的响应的数据 function connection(){ $.ajax({ typ ...

  8. android 中对apache httpclient及httpurlconnection的选择

    在官方blog中,android工程师谈到了如何去选择apache client和httpurlconnection的问题: 原文见http://android-developers.blogspot ...

  9. Java基础—异常处理总结

      异常处理是程序设计中一个非常重要的方面,也是程序设计的一大难点,从C开始,你也许已经知道如何用if...else...来控制异常了,也许是自发的,然而这种控制异常痛苦,同一个异常或者错误如果多个地 ...

  10. Tag file directory /struts-tags does not start with "/WEB-INF/tags"

    使用自定义标签,记得引用路径 <%@taglib prefix="s" uri="/struts-tags" %>