Mega Code Archive

 
Categories / C# Tutorial / Preprocessing Directives
 

Demonstrate #if, #endif, and #define

The #if and #endif directives enable conditional compilation. A symbol is true if it has been defined. A symbol is false if it has not been defined. If a symbol has been defined by a #define directive, the symbol true. The general form of #if is #if symbol-expression       statement sequence      #endif #define AAA   using System;    class MainClass {    public static void Main() {            #if AAA       Console.WriteLine("Compiled for experimental version.");      #endif          Console.WriteLine("This is in all versions.");    }  } Compiled for experimental version. This is in all versions.