-1

Is it possible when we can change the solution configuration from Debug and Release, we make certain chunk of code ignore by the compiler, which also means those chunk of code only run in Debug environment?

3 Answers3

2

You can use preprocessor directives like:

#if DEBUG
    // your code here
#endif
Selman Genç
  • 100,147
  • 13
  • 119
  • 184
0

indeed you can. use the #if DEBUG statement to only run if the configuration is in debug mode.

i.e:

#if DEBUG
// do some debug specific stuff
#endif
Ahmed ilyas
  • 5,722
  • 8
  • 44
  • 72
0

Yes, you can do this in several ways:

In Debug builds, both DEBUG and TRACE symbols are defined by default. In Release builds, only TRACE is defined.

  1. You can use the structure:
#if DEBUG
// do something in Debug builds only
#endif
  1. You can apply the Conditional attribute on methods (see http://msdn2.microsoft.com/en-us/library/system.diagnostics.conditionalattribute.aspx)

  2. You can use the Debug.xxx methods which only execute in debug builds