开发者

Conditional Attribute

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 thi开发者_运维百科s,

[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?


I am pretty sure you need to do:

[Conditional("Debug")] or [Conditional("DEBUG")]

Or you could define your own constant such as:

const string DEBUG = "DEBUG";

Then use that

[Conditional(DEBUG)]

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:

[Conditional("DEBUG")] // <- Works the DEBUG define
public static void Foo() {
    Console.WriteLine("Executed Foo");
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜