4

如何查找它是处于调试模式还是发布模式?还有其他方法可以找到吗?

    #if(DEBUG)
{
       Console.WriteLine("Debug mode");
       //Or Things to do in debug mode
}
    #else
{
       Console.WriteLine("Release mode");
       //Or Things to do in Release mode- May be to change the text, image 
}
#endif
4

2 回答 2

6

不,这是唯一的方法,但您需要正确的语法和大小写。您还可以检查是否附加了调试器。这是正确的语法:

#if DEBUG
    Console.Writeline("debug");
#else
    Console.Writeline("release");
#endif
    // You can also check if a debugger is attached, which can happen in either debug or release
    if (Debugger.IsAttached)
        Console.WriteLine("debugger attached");
于 2013-09-27T15:01:03.433 回答
1

您可以尝试使用 System.Diagnostics:

if (Debugger.IsAttached) {...?

于 2013-09-27T15:00:45.840 回答