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:
#elif lets you create a compound conditional directive. The #elif expression will be evaluated if neither the
preceding #if (C# Reference) nor any preceding, optional, #elif directive expressions evaluate to true. If a #elif
expression evaluates to true, the compiler evaluates all the code between the #elif and the next conditional
directive. For example:
#define VC7
//…
#if debug
Console.Writeline(“Debug build”);
#elif VC7
Console.Writeline(“Visual Studio 7”);
#endif
Incorrect:
Not B:
* System.Reflection.Assembly.GetExecutingAssembly Method
Gets the assembly that contains the code that is currently executing.
* Assembly.IsDefined Method
Indicates whether or not a specified attribute has been applied to the assembly.
* System.Dignostics.Debugger Class
Enables communication with a debugger.
Property: IsAttached
Gets a value that indicates whether a debugger is attached to the process.



Leave a Reply 5

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


Seamus

Seamus

Option B is correct

there is nothing like RELEASE in release mode unless it is explicitly defined using #define RELEASE in code

so #elif(RELEASE) will be false both in release and debug mode

Dayo

Dayo

B is incorrect. But for option D, it will always write output if in Debug mode but nothing will be printed in Release mode. So #elif(RELEASE) will be false when in release mode only.

hedss

hedss

B will always print Release mode, it should be D if it was correctly written.

dfffdgfd

dfffdgfd

Option D is the best option assuming #define is present (Checked all options in VS)

elu

elu

D is correct when you add #define RELEASE. B will show always release