You need to write a console application that meets the following requirements:
If the application is compiled in Debug mode, the console output must display Entering debug mode.
If the application is compiled in Release mode, the console output must display Entering release mode.
Which code should you use?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
Explanation:
Programmatically detecting Release/Debug mode (.NET)
Boolean isDebugMode = false;
#if DEBUG
isDebugMode = true;
#endif
http://stackoverflow.com/questions/654450/programmatically-detecting-release- debug-mode-net
I didn’t choose D because of the typo in it. ‘eliF’
My mistake, it’s not a typo. Lesson learned.
d
The correct answer is C.
Tested in VS
if (System.Reflection.Assembly.GetExecutingAssembly().IsDefined(typeof(System.Diagnostics.Debugger), false))
Console.WriteLine(“Entering debug mode”);
else Console.WriteLine(“Entering release mode”);
There is no RELEASE constant unless you define it yourself
https://stackoverflow.com/questions/507704/will-if-release-work-like-if-debug-does-in-c