我觉得这是一个简单的问题,所以我认为我失去了一些东西明显。我真的不用不完preprocessor指令,但我一直在寻找某人code这做,并认为这是我应该熟悉。
I think this is a simple question so I assume I'm missing something obvious. I don't really ever use preprocessor directives but I was looking at someones code which did and thought it was something I should be familiar with.
所以,我看了看MSDN的例子这里它具有code:
So I looked at the msdn example here it has the code:
#define DEBUG
// ...
#if DEBUG
Console.WriteLine("Debug version");
#endif
我的两个问题是:
My two questions are:
在上面为什么他们定义DEBUG的例子吗?我是在被你的调试v编译设置IM pression。释放模式? 在看它有的#define MYTEST
,然后如果它定义写入控制台依赖,但这是如何从只使用一个变量不同的另一个例子?我是什么在这里失踪?
in the example above why do they define DEBUG? I was under the impression that was set if you compile in debug v. release mode?
looking at the other example which has #define MYTEST
and then writes to the console dependent on if it 'defined', but how does this differ from just using a variable? What am I missing here?
感谢
我真的建议使用条件属性,而不是行内的#if语句。
I would actually recommend using the Conditional Attribute instead of inline #if statements.
[Conditional("DEBUG")]
private void DeleteTempProcessFiles()
{
}
这不仅是更清洁和更容易阅读,因为你最终不会有#如果,#else伪在您的code。此样式是不易出错或者在正常code编辑和以及逻辑流误差。
Not only is this cleaner and easier to read since you don't end up having #if, #else within your code. This style is less prone to errors either during normal code edits and well as logic flow errors.