Now here’s a trick that I didn’t know - you can use the [Conditional] attribute to suppress a method unless a given symbol is defined at compile time.

From the MSDN documentation:

Applying ConditionalAttribute to a method indicates … the method should not be compiled into Microsoft intermediate language (MSIL) unless the conditional compilation symbol that is associated with ConditionalAttribute is defined.

Mostly of use when you’re writing logging and other diagnostic code - indeed, major use in the framework seems to be in the Debug and Trace classes.

See details on MSDN at


blog comments powered by Disqus