开发者

Is there a better and safer way than using: #define DEBUG?

In one of my asp.Net pages I want to set some properties of a user control so that it behaves differently to make things easier and faster while I debug and test my page.

I want to compile the code block where I set my properties only if I am running the VS in DEBUG. I know I can use conditional compiling directives like:

#define DEBUG

#if DEBUG
        // some settings here
#else
              // some settings to be used in Released code
#endif

But the thing is I want to save myself from the risk of commenting out the define declaration.

Is there a safer wa开发者_如何学编程y than this? Thanks!


You shouldn't generally include the #define in your code - the point of having different Visual Studio project configurations is that they control what preprocessor symbols are defined.

Just build the Release or Debug configuration to control which bit of code is used.


You did wrong in your code. You will never run in the #else section because you always define the DEBUG symbol, so it has no sense to define the if when it's always true.

About safety, I see no threats in using #define DEBUG. Just remove it and use project configurations!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜