#if(DEBUG)VS System.Diagnostics.Debugger.IsAttached [英] #if (DEBUG) VS System.Diagnostics.Debugger.IsAttached
问题描述
在Visual Studio中使用 #if(DEBUG)
和 System.Diagnostics.Debugger.IsAttached
有什么区别?是否有设置 DEBUG
标志的情况,但未附加调试器,还是在 DEBUG $ c $时可以附加调试器的情况? c>标记未设置?
What is different between using #if (DEBUG)
and System.Diagnostics.Debugger.IsAttached
in visual studio? Are there cases of the DEBUG
flag being set, but no debugger attached, or cases when a debugger could be attached when the DEBUG
flag is not set?
推荐答案
#if DEBUG
确保发布版本中的程序集中根本不包含任何代码。此外, #if DEBUG
包含的代码始终在调试版本中运行-不仅是在调试器下运行。
#if DEBUG
ensures the code is not included in the assembly at all in release builds. Also, code included by #if DEBUG
runs all the time in a debug build - not just when running under a debugger.
Debugger.IsAttached
表示无论是调试版本还是发行版本,都包含该代码。
Debugger.IsAttached
means the code is included whether debug or release build. And a debugger can be attached to release builds to.
通常将两者一起使用。 #if DEBUG
通常用于日志记录之类的东西,或用于减少内部测试版本中的异常处理。 Debugger.IsAttached
往往仅用于决定是吞下异常还是向程序员显示它们-程序员的帮助多于其他任何东西。
It's common to use both together. #if DEBUG
is usually used for things like logging, or to reduce exception handling in internal test builds. Debugger.IsAttached
tends to just be used to decide whether to swallow exceptions or show them to a programmer - more of a programmer aid than anything else.
这篇关于#if(DEBUG)VS System.Diagnostics.Debugger.IsAttached的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!