Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

#elif (C# Reference)

#elif lets you create a compound conditional directive. The #elif expression will be evaluated if neither the preceding #if (C# Reference) nor any preceding, optional, #elif directive expressions evaluate to true. If a #elif expression evaluates to true, the compiler evaluates all the code between the #elif and the next conditional directive. For example:

#define VC7
//...
#if debug
    Console.Writeline("Debug build");
#elif VC7
    Console.Writeline("Visual Studio 7");
#endif

You can use the operators == (equality), != (inequality), && (and), and || (or), to evaluate multiple symbols. You can also group symbols and operators with parentheses.

#elif is equivalent to using:

#else
#if

Using #elif is simpler, because each #if requires a #endif (C# Reference), whereas a #elif can be used without a matching #endif.

See #if (C# Reference) for an example of how to use #elif.

Community Additions

ADD
Show:
© 2015 Microsoft