Applying System.Diagnostics.ConditionalAttribute to a method indicates to compilers that a call to the method should not be compiled into Microsoft intermediate language (MSIL) unless the conditional compilation symbol that is associated with System.Diagnostics.ConditionalAttribute is defined. You will get a compilation error in Visual Studio if you apply this attribute to a method that does not return void. Applying System.Diagnostics.ConditionalAttribute to an attribute indicates that the attribute should not be emitted to metadata unless the conditional compilation symbol is defined. Any arguments passed to the method or attribute are still type-checked by the compiler.

You can use the following techniques to define conditional compilation symbols:

Use compiler command-line options; for example, /define:DEBUG.

Use environment variables in the operating system shell; for example, set DEBUG=1.

Use pragmas in the source code; for example, define the compilation variable as follows: