Question about "#if DEBUG"

Hi, I'm using VS2013, C# and asp.net web form
I want to print out messages from application to be different when it's in Debug mode and when it's in Release mode.  I'm confused about how to use the #if DEBUG  statement.  Do I need to have "#define DEBUG " statement at the top of the main page aspx?  Reading this link just confuses me, https://msdn.microsoft.com/en-us/library/4y6tbswk.aspx    and   http://stackoverflow.com/questions/1734741/how-to-execute-code-only-in-debug-mode-in-asp-net 

I want the program to auto detect if it's in DEBUG mode but if I use the define statement does that always put it in DEBUG mode?
Thank you.

Does syntax like this is correct?
#if DEBUG
     output this message;
#else
    output this other message;
lapuccaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MlandaTCommented:
The DEBUG is by default set when you are compiling the debug configuration in VS however you can set it manually for any configuration

Visual studio build configuration
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MlandaTCommented:
You do not have to set it manually. You just change your build configuration to Debug or ReleaseBuild configurationYour syntax is correct... Well mostly.... You always need a #endif... Whether you use #else or not.

#if DEBUG
     output this message;
#else
    output this other message;
#endif
0
lapuccaAuthor Commented:
Thank you.
0
Fernando SotoRetiredCommented:
To your question :

Does syntax like this is correct?
#if DEBUG
     output this message;
#else
    output this other message;

If before this code you have #define DEBUG then "output this message;" will be executed if it is not appear before the statement then " output this other message;" this will be executed.
2
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.