Will #if RELEASE work like #if DEBUG does in C#?

前端 未结 11 1746
时光说笑
时光说笑 2020-11-30 17:39

In all the examples I\'ve seen of the #if compiler directive, they use \"DEBUG\". Can I use \"RELEASE\" in the same way to exclude code that I don\'t want to run when compi

11条回答
  •  一生所求
    2020-11-30 18:06

    No, it won't, unless you do some work.

    The important part here is what DEBUG really is, and it's a kind of constant defined that the compiler can check against.

    If you check the project properties, under the Build tab, you'll find three things:

    • A text box labelled "Conditional compilation symbols"
    • A check box labelled "Define DEBUG constant"
    • A check box labelled "Define TRACE constant"

    There is no such checkbox, nor constant/symbol pre-defined that has the name RELEASE.

    However, you can easily add that name to the text box labelled Conditional compilation symbols, but make sure you set the project configuration to Release-mode before doing so, as these settings are per configuration.

    So basically, unless you add that to the text box, #if RELEASE won't produce any code under any configuration.

提交回复
热议问题