
- 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/then directives for debug vs release 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).
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(string[] args){ #if DEBUG Console.WriteLine("Mode=Debug"); #else Console.WriteLine("Mode=Release"); #endif Console.ReadLine(); } }
Output
if in Debug Mode Mode=Debug if in Release Mode Mode=Release
- Related Articles
- Debug Class vs Debugger Class in C#
- What is #if DEBUG and How to use it in C#?
- What is early token release and delayed token release?
- What are JSP Directives?
- What is TCP Connection Release?
- What are C# pre-processor directives?
- How to use #if..#elif…#else…#endif directives in C#?
- What is an Agile Release Train (ART)?
- What is a Multi-Release jar(mrjar) in Java 9? \n
- C/C++ Preprocessor Directives
- How to use directives in angular 8?
- Like in the case of female the period of ovulation is 28 to 30 days then what about the males , what is the period time of the release of sperms?
- What is difference between vs. ?
- Explain the pre-processor directives in C language
- How to create custom directives in Angular 8?

Advertisements