Demonstrate #elif : elif « Preprocessing Directives « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Preprocessing Directives » elif 
16.2.1.Demonstrate #elif
  1. The #else directive establishes an alternative if #if fails.
  2. #else marks both the end of the #if block and the beginning of the #else block.
  3. The #elif directive means "else if".
  4. The #elif directive establishes an if-else-if chain for multiple compilation options.
  5. #elif is followed by a symbol expression.
  6. There can be only one #endif associated with any #if.
  7. If the expression is true, that block of code is compiled, and no other #elif expressions are tested.

The general form for #elif is

#if symbol-expression 
      statement sequence 
    #elif symbol-expression 
      statement sequence 
    #elif symbol-expression
      statement sequence 
    #elif symbol-expression
      statement sequence 
    #elif symbol-expression 
    .
    .
    .
    #endif
#define AAA 
#define RELEASE 
 
using System; 
 
class MainClass 
  public static void Main() { 
     
    #if AAA 
      Console.WriteLine("Compiled for AAA version.")
    #elif RELEASE 
      Console.WriteLine("Compiled for release.")
    #else 
      Console.WriteLine("Compiled for internal testing.")
    #endif 
 
    #if BBB && !RELEASE 
       Console.WriteLine("BBB version.")
    #endif 
   
    Console.WriteLine("This is in all versions.")
  
}
Compiled for AAA version.
This is in all versions.
16.2.elif
16.2.1.Demonstrate #elif
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.