你可以简单地使用这样的#if DEBUG指令
#if DEBUG
//code here only executes in debug
#endif
Run Code Online (Sandbox Code Playgroud)
因此,如果你想要一些在DEBUG中运行的代码和一些在RELEASE中运行的代码,你可以这样做:
#if DEBUG
//code here only executes in debug
#else
//code here only executes in release
#endif
Run Code Online (Sandbox Code Playgroud)
正如DAKL 解释的那样,您也可以使用Conditional属性.