In Visual Studio, debug mode and release mode are different configurations for building .Net projects.
Select Debug mode to step through your .Net project, and Release mode for final build assembly files (.dll or .exe).
Debug mode does not optimize the binaries it generates because the relationship between the source code and the generated instructions is more complex.
This allows breakpoints to be set accurately and allows programmers to execute code one line at a time.
The program's debug configuration is compiled with full symbolic debugging information, which helps the debugger determine where it is in the source code
The program's release configuration has no symbolic debugging information and is fully optimized .
From the Build menu, select Configuration Manager, and then select Debug or Release.
Or
On the toolbar, select "Debug" or "Release" from the "Solution Configuration" list
The following code #if debug is written only in The code will only be executed when it is running in debug mode
If the code is running in release mode#if Debug will be false and the code will not be executed. The code exists here
class Program { static void Main() { #if DEBUG Console.WriteLine("You are in debug"); #endif Console.ReadKey(); } }
If the program is running in debug mode, the If block will return true
and print "You are in debug"
If the program is not in debug mode then if debug returns false
The above is the detailed content of What is #if DEBUG and how to use it in C#?. For more information, please follow other related articles on the PHP Chinese website!