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!