How to execute in DEBUG only?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mynkow
    New Member
    • Jul 2007
    • 37

    How to execute in DEBUG only?

    I want to execute some code only in debug mode. I found this:
    Code:
    [ Conditional("Debug") ]
    public void DebugThis(){...}
    But this refers for methods. I want to say something like this:

    Code:
    #if DEBUG
          code...
    #endif
    The code there seems to be commented. What I have to do?

    Thank you!
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    There is a boolean that can tell you if you are running in debug or not.

    System.Diagnost ics.Debugger.Is Attached

    You can use that to control some code, but I don't think there is a way to keep it out of the compile like you could with # directives.

    Comment

    • mynkow
      New Member
      • Jul 2007
      • 37

      #3
      10x alot. It works for me :)

      Comment

      Working...