Tips for debugging vs.net # define debug (suitable for beginners)

Source: Internet
Author: User

In most cases, we can use breakpoints in vs.net to solve debugging problems. However, in some cases, you may need to manually output some information for debugging reference. Have you ever completed the debugging, forgot to delete an output statement?

The following tips can solve this problem:

# Define debug
Using system;

Namespace debugdemo
{
Class Program
{
Static void main (string [] ARGs)
{
# If debug
Console. writeline ("I am debugging information ");
# Endif
Console. writeline ("this is a normal functionCode...");

Console. Read ();
}
}
}

Note the section with "#". Here we first define a debug symbol, and then use # if... # endif makes a judgment, meaning: If debug is defined, execute

Console. writeline ("I am debugging information ");

This sentence,ProgramThe output is as follows:

 

I am debugging information
Here is the normal function code...

 

Someone may be worried: "Cut, isn't the output like this without adding these lines? "

 

The key time is: The program passes debugging. When the program is officially released, change the initial # define debug# UNDEF debug,If you run it again, all debugging information is lost!

 

Have you learned? Of course # There are other usage, such as the common # region... # endregion. For more instructions, refer to the msdn documentation.

 

Finally, I would like to add a tip: In addition to using breakpoints to view the value of local variables, you can also useSystem. Diagnostics. Debug. writeline ("debugging information, such as the value of a temporary variable ");Output results to the output window (ctrol + W + O can call up the window), especially when debugging a massive number of cycles, if you do not want to press the breakpoint to soft, use this effort

 

Afterwards: This is hydrology, and experts can bypass it!

 

 

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.