Using the #elif Directive

When you check whether a conditional compilation symbol is defined using the #if#else and #endif directives, you can include additional clauses within the scope of the #if directive by using the #elif directive.  The #elif directive adds an additional expression to check, if any earlier expressions evaluate to false.
In the example below, we check both the DOGSBARK and the DOGSWAG symbols to determine which line to compile.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//#define DOGSBARK
#define DOGSWAG
 
using System;
using DogLibrary;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            Dog d1 = new Dog("Kirby", 12);
#if DOGSBARK
            d1.Bark();
#elif DOGSWAG
            d1.WagTail();
#else
            d1.JustSitThere();
#endif
        }
    }
}



You can include as many #elif clauses as you like.