Conditional attribute

Quick question with C #, I would like to know that in my project> Properties> Assembly there is a check "Define DEBUG constant" , so if I check this and then I do it,

[Conditional(DEBUG)]
public static void Foo() {
      Console.WriteLine("Executed Foo");
}

See "DEBUG" for its DEBUG constant . So will it be good? Or do I need to add "DEBUG" to conditional compilation symbols in the project settings? Or #define ?

+3
source share
2 answers

I am sure you need to do:

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

, :

const string DEBUG = "DEBUG";

[Conditional(DEBUG)]

#define DEBUG. . # MSDN.

+5

:

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

Source: https://habr.com/ru/post/1727763/


All Articles