Csharp/CSharp Tutorial/Preprocessing Directives/if

Материал из .Net Framework эксперт
Версия от 12:17, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Demonstrate #else.

#define AAA 
#define BBB 
 
using System; 
 
class Test { 
  public static void Main() { 
     
    #if AAA 
      Console.WriteLine("Compiled for AAA version."); 
    #else 
      Console.WriteLine("Compiled for release."); 
    #endif 
 
    #if AAA && BBB 
       Console.Error.WriteLine("Testing AAA and BBB version."); 
    #else 
       Console.Error.WriteLine("Not (AAA and BBB) version."); 
    #endif 
   
    Console.WriteLine("This is in all versions."); 
  } 
}
Compiled for AAA version.
Testing AAA and BBB version.
This is in all versions.

Demonstrate #if, #endif, and #define.

  1. The #if and #endif directives enable conditional compilation.
  2. A symbol is true if it has been defined.
  3. A symbol is false if it has not been defined.
  4. 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