The Conditional Attribute : Conditional Attribute « Attribute « C# / CSharp Tutorial






  1. The Conditional Attribute allows you to create conditional methods.
  2. A conditional method is invoked only when a specific symbol has been defined via #define.
  3. Otherwise, the method is bypassed.
  4. A conditional method offers an alternative to conditional compilation using #if.
  5. Conditional is another name for System.Diagnostics.ConditionalAttribute.
  6. To use the Conditional attribute, you must include the System.Diagnostics namespace.

Conditional methods have a few restrictions.

  1. Conditional methods must return void.
  2. Conditional methods must be members of a class, not an interface.
  3. Conditional methods cannot be preceded with the override keyword.
10.3.Conditional Attribute
10.3.1.The Conditional Attribute
10.3.2.Demonstrate the Conditional attribute
10.3.3.The Conditional attribute setting in Compile parameter