Mega Code Archive

 
Categories / C# Tutorial / Attribute
 

The Conditional Attribute

The Conditional Attribute allows you to create conditional methods. A conditional method is invoked only when a specific symbol has been defined via #define. Otherwise, the method is bypassed. A conditional method offers an alternative to conditional compilation using #if. Conditional is another name for System.Diagnostics.ConditionalAttribute. To use the Conditional attribute, you must include the System.Diagnostics namespace. Conditional methods have a few restrictions. Conditional methods must return void. Conditional methods must be members of a class, not an interface. Conditional methods cannot be preceded with the override keyword.