Csharp/CSharp Tutorial/Preprocessing Directives/if
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.
- 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