views:

90

answers:

2

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?

+3  A: 

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.

James
+1  A: 

You need to add double quotes for this to work:

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