I am using C#. Need to know about the usage of #if.
The code details is:
#if
//logic code
#else
//logic code
#endif
//logic code
I cant understand how its working in debugging mode.
Waiting for quick response. Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
“#if DEBUG” works because Visual Studio creates a Pre-processor directive with the name DEBUG based on current Solution’s configuration(either in Release Mode or Debug Mode) – Solution configuration have option to enable/disable DEBUG and TRACE constants and to associate them with solution configurations.
You can use this directive anywhere in code and it help eliminating code based on mode at build time. and this is really a common scenario where some times we need a code to run only in debug mode but not in release mode. more details you can find here
http://dotnetfacts.blogspot.com/2009/05/determine-debug-mode-in-net.html
Regards,
Edit: Thanks to Paul Alexander for clarification