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

前端 未结 11 1771
时光说笑
时光说笑 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 17:40

    You can create you own conditional compile-time symbols (any name you like). Go to the "project Build dialog", located in the project properties box, menu option: Project->[projectname] Properties...

    You can also define them "at the top of the C# code file". Like:

    #define RELEASE
    // or
    #undef RELEASE
    

    you can use the symbol in a #if statement:

    #if RELEASE
    // code ...
    #elif …
    // code ...
    #endif
    
    // or
    
    #if !RELEASE
    // code ...
    #endif
    

提交回复
热议问题