Two debug methods for C #

Source: Internet
Author: User

First: You need to change the debug method to debug
Code with #if DEBUG package

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.IO;namespacesplitpackage{ Public Static classEnvconfig {StaticEnvconfig () {#ifDEBUGToolsPath=@"D:\workspace\shopstyle\tool";#elseToolsPath=environment.currentdirectory;#endif            intRootidx = Toolspath.lastindexof (@"\"); if(Rootidx >0) {RootPath= Toolspath.substring (0, ROOTIDX); }        }         Public Static stringToolsPath {Get;Private Set; }  Public Static stringTmplatefile {Get{returnPath.Combine (ToolsPath,@"template\default.pm"); } }         Public Static stringRootPath {Get;Private Set; }  Public Static stringModulepath {Get{returnPath.Combine (RootPath,"Module"); } }         Public Static stringConfigpath {Get{returnPath.Combine (RootPath,"conf"); } }    }}

The second type:
Using macro Definitions

#define DEBUG//C # Macro definition must appear before all code. Currently we only let the debug macro work.
Using System.Diagnostics; This package must be included

#defineDEBUGusingSystem.Diagnostics;namespacetestconsole{classToolKit {[ConditionalAttribute ("LI")]//the long notation of attribute name[ConditionalAttribute ("DEBUG")]         Public Static voidMethod1 () {Console.WriteLine ("Created by Li, buged.11"); } [ConditionalAttribute ("LI")] [ConditionalAttribute ("Nobug")]         Public Static voidMethod2 () {Console.WriteLine ("Created by Li, Nobug."); } [Conditional ("ZHANG")]//short notation of attribute name[Conditional ("DEBUG")]         Public Static voidMethod3 () {Console.WriteLine ("Created by Zhang, buged.11"); } [Conditional ("ZHANG")] [Conditional ("Nobug")]         Public Static voidMethod4 () {Console.WriteLine ("Created by Zhang, Nobug."); }    }        Static voidMain (string[] args)            {toolkit.method1 ();            TOOLKIT.METHOD2 ();            Toolkit.method3 ();        TOOLKIT.METHOD4 (); }    }}

Two debug methods for C #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.