条件属性
一个简单的 C# 问题,我想知道在我的项目中 >属性>构建,有一个检查“定义DEBUG常量”,所以如果我检查它然后执行此操作,
[Conditional(DEBUG)]
public static void Foo() {
Console.WriteLine("Executed Foo");
}
看到它不是“DEBUG”它是DEBUG恒定。那么这样可以吗?或者我是否必须在项目设置的条件编译符号中添加“DEBUG”?或者#define它?
A quick C# question, I would like to know that in my project > Properties > Build, there is a check "Define DEBUG constant", so if I check that and then do this,
[Conditional(DEBUG)]
public static void Foo() {
Console.WriteLine("Executed Foo");
}
See it's not "DEBUG" its the DEBUG constant. So will this be okay? Or do I have to add the "DEBUG" in the Conditional Compilation Symbols in the Project settings? Or #define it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很确定您需要这样做:
或者您可以定义自己的常量,例如:
然后使用它
这必须附有
#define DEBUG
声明。请参阅 MSDN 上的条件 C#。I am pretty sure you need to do:
Or you could define your own constant such as:
Then use that
This will have to be accompanied by the
#define DEBUG
declaration. See Conditional C# on MSDN.您需要添加双引号才能使其工作:
You need to add double quotes for this to work: