Demonstrate #if, #endif, and #define. : If : Preprocessing Directives C# Examples


C# Examples » Preprocessing Directives » If »

 

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.");  
    }  
}
    
   
  
   



Output

Compiled for experimental version.
This is in all versions.


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Preprocessing Directives
» If