C # test Code # if debug uses

Source: Internet
Author: User

code example:
#if DEBUG Console.WriteLine ("debug:11111111111"); #else Console.WriteLine ("release:222222222222"); #endif

In this code, if the run mode is DEBUG, the code outputs "debug:11111111111"

In this code, if the run mode is Release, the "release:222222222222" setting is output, DEBUG and Release are set directly in the project configuration if "Define debug constant (U)" is set in the project (Define debug Constant (U)) is unchecked, you can use debug code in debug mode. Create   in debug code with properties----right--project---you can also add some special effects (you don't have to play the effects if the conditions are met), such as:
 int  i = 10    #if  Debug            Debug.Assert (i  < 9  );             Console.WriteLine (  "  debug:11111111111   " );   #else              Console.WriteLine (  " release : 222222222222     #endif  

If you run this code, there are special effects:

1. If the point retries, will automatically locate the error location, whether there is no breakpoint; 2. If the point is ignored, the next step is continued; 3. If the point is terminated, the software is shut down directly. PS: If setting figure 1 does not work, see if the configuration of release and debug is set in the Solution property page is Debug. You can restore it: 1. Configuration Manager, configuration Properties---Properties--right-click Solutions, configuration Managers 2. Build--Configuration Manager

C # test Code # if debug uses

Related Article

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.