Which code should you use?

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?

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



Leave a Reply 5

Your email address will not be published. Required fields are marked *


Huggy Berra

Huggy Berra

I didn’t choose D because of the typo in it. ‘eliF’

Huggy Berra

Huggy Berra

My mistake, it’s not a typo. Lesson learned.

Seamus

Seamus

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”);