[英]C# Debug and release mode
How to find whether it is in debug mode or release mode? 如何查找是处于调试模式还是发布模式? Are there any other ways to find it?
有没有其他方法可以找到它?
#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
No that's the only way, but you need to have the syntax and capitalization correct. 不,这是唯一的方法,但你需要正确的语法和大小写。 You can also check whether the debugger is attached.
您还可以检查调试器是否已附加。 Here is the correct syntax:
这是正确的语法:
#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");
You could try using System.Diagnostics: 您可以尝试使用System.Diagnostics:
if (Debugger.IsAttached) {...
? if (Debugger.IsAttached) {...
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.