
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What is #if DEBUG and How to use it in C#?
In Visual Studio Debug mode and Release mode are different configurations for building your .Net project.
Select the Debug mode for debugging step by step their .Net project and select the Release mode for the final build of Assembly file (.dll or .exe).
The Debug mode does not optimize the binary it produces because the relationship between source code and generated instructions is more complex.
This allows breakpoints to be set accurately and allows a programmer to step through the code one line at a time.
The Debug configuration of your program is compiled with full symbolic debug information which help the debugger figure out where it is in the source code
The release configuration of your program has no symbolic debug information and is fully optimized.
To change the build configuration
From the Build menu, select Configuration Manager, then select Debug or Release.
or
On the toolbar, choose either Debug or Release from the Solution Configurations list
The code which is written inside the #if debug will be executed only if the code is running inside the debug mode
If the code is running in the release mode then the #if Debug will be false and it will not execute the code present inside this
Example
class Program { static void Main() { #if DEBUG Console.WriteLine("You are in debug"); #endif Console.ReadKey(); } }
If the Program is running in the debug mode then the If bloc will return true
And prints "You are in debug"
If the program is not in the debug mode then If Debug return false
- Related Articles
- What is the ‘if’ statement in Java and how to use it?
- What is if/then directives for debug vs release in C#?
- What is the ‘if...else if...else’ statement in Java and how to use it?
- What is the ‘if else’ statement in Java and how to use it?
- What is the ‘nested if’ statement in Java and how to use it?
- What is SignalR and how to use it?
- How to debug a core in C/C++?
- What is method hiding in Java and how to use it?
- SWR Meter – What is It & How to Use It
- What is use of fluent Validation in C# and how to use in C#?
- What is electricity and how we use it?
- What is a break statement in Java and how to use it?
- What is a continue statement in Java and how to use it?
- What is the type conversion operator ( ) in Java and how to use it?
- What is a switch case statement in Java and how to use it?
