#elif Preprocessor Directive in C#

By Santhosh N

This explains the Microsoft .Net C# preprocessor directive, #elif and its usage for Conditional Compilation in the C# Language by the developers.

The #elif preprocessor directive is similar to #else and #if directive in combination. This is used to evaluate the statements places between this and next conditional directive.

The #elif has an advantage over using #else and #if in combination as there is no need to use #endif for the #if directive explicitly for each #if directive.

Ex:
#if DEBUG
    // statements to run only while debugging
#elif CUSTOMSYMBOL
    // statements to run when CUSTOMSYMBOL is true, here CUSTOMSYMBOL is a custom defined symbol.
#endif

Related FAQs

This explains the Microsoft .Net C# preprocessor directive, #if, #else and #endif and its usage for Conditional Compilation in the C# Language by the developers.
This list out all the available preprocessor directives in Microsoft .Net C# Language which helps developers to conditionally compile the applications while coding.
This explains how to find the version of the Microsoft Excel that has been installed in the system.
This explains how to make C# windows Forms TextBox accept only numeric values.
This explains the location of the Strong Name Generator Tool, sn.exe in Microsoft .Net 4.0 version when Visual Studio 2010 is installed.
#elif Preprocessor Directive in C#  (1039 Views)