

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use #if..#elif…#else…#endif directives in C#?
All preprocessor directives begin with #, and only white-space characters may appear before a preprocessor directive on a line. Preprocessor directives are not statements, so they do not end with a semicolon (;).
#if
The #if directive allows testing a symbol or symbols to see if they evaluate to true.
#else
It allows to create a compound conditional directive, along with #if.
#elif
It allows creating a compound conditional directive.
#endif
The #endif specifies the end of a conditional directive.
The following is an example showing the usage of #if, #elif, #else and #endif directives −
Example
#define One #undef Two using System; namespace Demo { class Program { static void Main(string[] args) { #if (One && TWO) Console.WriteLine("Both are defined"); #elif (ONE && !TWO) Console.WriteLine("ONE is defined and TWO is undefined"); #elif (!ONE && TWO) Console.WriteLine("ONE is defined and TWO is undefined"); #else Console.WriteLine("Both are undefined"); #endif } } }
Output
Both are undefined
- Related Questions & Answers
- Ternary operator ?: vs if…else in C/C++
- How to optimize nested if...elif...else in Python?
- Where to put comments in an if...elif..else construct?
- C Programming for Sum of sequence 2, 22, 222, ………
- Display records from MySQL stored Procedure with IF…THEN…END IF statements
- What is the syntax of Python if...elif...else statement?
- n-th term of series 1, 17, 98, 354…… in C++
- How to use #error and #warning directives in C#?
- How to use if/else condition in select in MySQL?
- What is the ‘if...else if...else’ statement in Java and how to use it?
- Program to find N-th term of series 7, 21, 49, 91, 147, 217, …… in C++
- Queries to check if substring[L…R] is palindrome or not in C++
- How to correctly use INSERT INTO … SELECT in MySQL to avoid Error 1064?
- Queries to check if substring[L…R] is palindrome or not in C++ Program
- How to use ‘else if ladder’ conditional statement is C language?
Advertisements