Preprocessor - #else


The #else works much like the else in C#. It establishes an alternative when the symbol expression in a #if evaluates to false. The following program illustrates the use of #else.

// Preprocessor3 - #else

#define Symbol1

using System;

class Program
{
    static void Main()
    {
#if Symbol1
        Console.WriteLine("Symbol1 defined");
#else
        Console.WriteLine("Symbol1 not defined");
#endif

#if Symbol1 && Symbol2
        Console.WriteLine("Symbol1 and Symbol2 defined");
#else
        Console.WriteLine("Symbol1 or Symbol2 not defined");
#endif
    }
}

The program prints out the following.

Symbol1 defined
Symbol1 or Symbol2 not defined