Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# if/then directives for debug vs release

In Solution properties, I have Configuration set to "release" for my one and only project.

At the beginning of the main routine, I have this code, and it is showing "Mode=Debug". I also have these two lines at the very top:

#define DEBUG  #define RELEASE 

Am I testing the right variable?

#if (DEBUG)             Console.WriteLine("Mode=Debug");  #elif (RELEASE)             Console.WriteLine("Mode=Release");  #endif 

My goal is to set different defaults for variables based on debug vs release mode.

like image 582
NealWalters Avatar asked Jan 20 '10 19:01

NealWalters


People also ask

Bahasa C digunakan untuk apa?

Meskipun C dibuat untuk memprogram sistem dan jaringan komputer namun bahasa ini juga sering digunakan dalam mengembangkan software aplikasi. C juga banyak dipakai oleh berbagai jenis platform sistem operasi dan arsitektur komputer, bahkan terdapat beberepa compiler yang sangat populer telah tersedia.

Apa yang dimaksud dengan huruf C?

C adalah huruf ketiga dalam alfabet Latin. Dalam bahasa Indonesia, huruf ini disebut ce (dibaca [tʃe]).


1 Answers

DEBUG/_DEBUG should be defined in VS already.

Remove the #define DEBUG in your code. Set preprocessors in the build configuration for that specific build.

The reason it prints "Mode=Debug" is because of your #define and then skips the elif.

The right way to check is:

#if DEBUG     Console.WriteLine("Mode=Debug");  #else     Console.WriteLine("Mode=Release");  #endif 

Don't check for RELEASE.

like image 85
psychotik Avatar answered Oct 08 '22 12:10

psychotik