- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements