如何查找是处于调试模式还是发布模式?有没有其他方法可以找到它?
#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
答案 0 :(得分: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");
答案 1 :(得分:1)
您可以尝试使用System.Diagnostics:
if (Debugger.IsAttached) {...
?