Export (0) Print
Expand All

#elif

#elif lets you create a compound conditional directive. The #elif expression will be evaluated if neither the preceding #if 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 directive.

#elif symbol [operator symbol]...

where:

symbol
The name of the symbol you want to test. You can also use true and false. symbol can be prefaced with the negation operator. For example, !true will evaluate to false.
operator (optional)
You can use the following operators to evaluate multiple symbols:

== (equality)

!= (inequality)

&& (and)

|| (or)

You can group symbols and operators with parentheses.

Remarks

#elif is equivalent to using:

#else
#if

But using #elif is simpler because each #if requires a #endif, whereas a #elif can be used without a matching #endif.

Example

See #if for an example of how to use #elif.

See Also

C# Preprocessor Directives

Show:
© 2014 Microsoft