C# 的两种debug 方法

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

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;  //必须包含这个包

#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();
        }
    }
}
时间: 2024-08-06 16:05:42

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

C#中的两种debug方法介绍

第一种:需要把调试方法改成debug 代码用 #if DEBUG 包裹 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&

基于Apache+Tomcat负载均衡的两种实现方法

Apache+Tomcat实现负载均衡的两种实现方法 如果我们将工作在不同平台的apache能够实现彼此间的高效通信,因此它需要一种底层机制来实现--叫做apr Apr的主要目的就是为了其能够让apache工作在不同的平台上,但在linux上安装apache的时候通常都是默认安装的 [[email protected] ~]#rpm -qi aprName                 :apr                                        Relocation

OGG的Director web hang住的两种解决方法

OGG的Director web hang住的两种解决方法: OGG的Director web hang住的解释:是指web界面能登陆进去,但是看得刷新日期是很久之前的日期,并且该日期不变化. OGG的Director web hang住 的情况之一: 参考如下的mos文章: Director web displaying "Error 500-Internal Server Error". Domain log has Cannot open paging store. (Doc I

git两种合并方法 比较merge和rebase

18:01 2015/11/18git两种合并方法 比较merge和rebase其实很简单,就是合并后每个commit提交的id记录的顺序而已注意:重要的是如果公司用了grrit,grrit不允许用merge,所以好像都是用rebase却别讲解,比如:在服务器上的develop分支有多人在开发,你们同时clone或pull下来最新代码,但是开发进度不一样,你在开发一个任务的时候其他人提交了编号为1,2的commit和push,你现在开发完了也要提交,你的提交编号是3,4(注意:编号不代表顺序现实

Eclipse web工程创建步骤及两种部署方法

1.Eclipse创建web工程步骤 (1)参考1(2)参考2 2.web工程两种部署方法 (1)部署方法同1中所述 (2)部署到Tomcat Server的webapps目录下的方法

JAVA EE 项目经常使用知识 之AJAX技术实现select下拉列表联动的两种使用方法(让你真正理解ajax)

ajax 下拉列表联动的使用方法. ajax的定义: AJAX 是一种用于创建高速动态网页的技术. 通过在后台与server进行少量数据交换,AJAX 能够使网页实现异步更新.这意味着能够在不又一次载入整个网页的情况下,对网页的某部分进行更新. ajax效果的一个样例: 区域为空的时候,维护人情况: 选了一个区域后的情况:(选 舒城县 联带出来的维护人员 小刘) 一.原生态的js实现 XMLHttpRequest 是 AJAX 的基础 XMLHttpRequest 对象 全部现代浏览器均支持 X

MVC4.0中下来列表框的,两种使用方法DropDownList

后台控制器代码 public ActionResult Drop() { var list = new List<SchoolInfo>(); list.Add(new SchoolInfo() { SchoolID = 1, SName = "北京大学" }); list.Add(new SchoolInfo() { SchoolID = 2, SName = "上海大学" }); var model = new UserViewInfo(); mod

uboot学习之二----主Makefile学习之四----两种编译方法:原地编译和单独输出文件夹编译

第57-123行: 57 # 58 # U-boot build supports producing a object files to the separate external 59 # directory. Two use cases are supported: 60 # 61 # 1) Add O= to the make command line 62 # 'make O=/tmp/build all' 63 # 64 # 2) Set environement variable

hdu3572--Task Schedule(最大流+两种优化方法,dinic)

Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3651    Accepted Submission(s): 1271 Problem Description Our geometry princess XMM has stoped her study in computational geometry t