The preprocessor directives send the compiler instructions to preprocess the data before the actual compilation begins.
All preprocessor directives start with #, and only white-space characters will appear on a line before a preprocessor directive. Preprocessor instructions are not statements, so the semicolon (;) does not end with them.
There is no independent preprocessor in the C # compiler, but the directives are processed as if there were one. The preprocessor directives are used in C # in order to assist in conditional compilation. They are not used for building macros, unlike the C and C++ directives. The only instruction on a line needs to be a preprocessor directive.
Preprocessor directives in C# :
It defines a sequence of characters, called symbol.
It allows you to undefine a symbol.
It allows testing a symbol or symbols to see if they evaluate to true.
It allows to create a compound conditional directive, along with #if.
It allows creating a compound conditional directive.
Specifies the end of a conditional directive.
It lets you modify the compiler's line number and (optionally) the file name output for errors and warnings.
It allows generating an error from a specific location in your code.
It allows generating a level one warning from a specific location in your code.
It lets you specify a block of code that you can expand or collapse when using the outlining feature of the Visual Studio Code Editor.
It marks the end of a #region block.
# define preporvessor-
Symbolic constants are generated via the # define preprocessor directive.
# define allows you to define a symbol such that the expression is set to true by using the symbol as the expression passed to the # if directive.
Its syntax is the following-
2. Conditional directive -
To create a conditional directive, you can use the directive # if. Conditional criteria are helpful in checking a symbol or symbols to verify if they are valid. If true is evaluated, all the code between # if and the next directive is evaluated by the compiler.
Syntax for conditional directive is −
#if symbol [operator symbol]...
There, the symbol is the name of the symbol to be evaluated. You may also use true and false or the negation operator prepends the symbol.
The symbol of the operator is the operator used for the symbol evaluation. Operators can be any of the following
= = (equalities)
! = (inequalities)
& & (and)
You can also group symbols with parentheses and operators. For compiling code for a debug build or when compiling for a particular configuration, conditional directives are used. A conditional, conditional directive.