C#中的两种debug方法介绍

所属分类: 软件编程 / C#教程 阅读数: 41
收藏 0 赞 0 分享

第一种:需要把调试方法改成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();
    }
  }
}
更多精彩内容其他人还在看

C#使用oledb读取excel表格内容到datatable的方法

这篇文章主要介绍了C#使用oledb读取excel表格内容到datatable的方法,涉及C#操作oledb及datatable的相关技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

C#使用oledb操作excel文件的方法

这篇文章主要介绍了C#使用oledb操作excel文件的方法,涉及C#中oledb操作excel的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#使用IHttpModule接口修改http输出的方法

这篇文章主要介绍了C#使用IHttpModule接口修改http输出的方法,涉及C#操作IHttpModule接口的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#给图片加水印的简单实现方法

这篇文章主要介绍了C#给图片加水印的简单实现方法,涉及C#操作图片的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#生成随机数的方法小结

这篇文章主要介绍了C#生成随机数的方法,实例总结了C#生成随机数的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#使用jQuery实现无刷新评论提交的方法

这篇文章主要介绍了C#使用jQuery实现无刷新评论提交的方法,涉及C#结合jQuery进行Ajax操作的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#读取中文文件出现乱码的解决方法

这篇文章主要介绍了C#读取中文文件出现乱码的解决方法,涉及C#中文编码的操作技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#图像对比度调整的方法

这篇文章主要介绍了C#图像对比度调整的方法,涉及C#实现图像对比度操作的相关技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

C#图像灰度级拉伸的方法

这篇文章主要介绍了C#图像灰度级拉伸的方法,涉及C#灰度操作的相关技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

C#图像线性变换的方法

这篇文章主要介绍了C#图像线性变换的方法,涉及C#操作图像线性变换的相关技巧,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多