Use the Conditional attribute with define : define « Preprocessing Directives « C# / CSharp Tutorial






#define USE_METHOD_1

using System;
using System.Diagnostics;

class MainClass
{

  [Conditional("USE_METHOD_1")]
  public static void Method1()
  {
    Console.WriteLine("In Method 1");
  }

  public static void Main() 
  {
      Console.WriteLine("In Main");
    Method1();
  }
}
In Main
In Method 1








16.1.define
16.1.1.A list of preprocessor commands available in C#:
16.1.2.Preprocessing Directives: define
16.1.3.Use a symbol expression.
16.1.4.Use the Conditional attribute with define