Windows 8应用程序正在调试

una*_*ity 0 c# windows-8

有没有办法检查app.cs是app的调试或部署的状态?

或者问题是我只想在调试应用程序时才能识别一段代码.

Pat*_*lug 5

你可以简单地使用这样的#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属性.