Use Conditional attribute - CSharp Custom Type

CSharp examples for Custom Type:Attribute

Description

Use Conditional attribute

Demo Code

// csc /define:DEBUG Main.cs
using System;/*from ww  w.j a  v a2 s.  c o  m*/
using System.Diagnostics;   //The ConditionalAttribute lives here
public class Foo {
   [Conditional("DEBUG")]
   public void OnlyWhenDebugIsDefined( ) {
      Console.WriteLine("DEBUG is defined");
   }
}
public class AttributeTest {
   public static void Main( ) {
      Foo f = new Foo( );
      f.OnlyWhenDebugIsDefined( );
   }
}

Related Tutorials