Preprocessor Directives in C#
Preprocessor Directives in C#
Preprocessor directives are a block of statements that are handled before the actual
compilation process starts. They give some instructions to the compiler on the
compilation process, error or warning handling etc.
Preprocessor directives begin with a hash symbol (#) and do not contain the
semicolon at the end as they are not statements. They are instead terminated by a new
line.
Some of the preprocessor directives in C# are given as follows:
The #if directive compiles the code between the directives only
#if
if the specified symbol is defined.
#elif The #elif is a compound conditional directive that is evaluated if neither the
preceding #if nor any preceding optional #elif directive expressions evaluate to true.
The #endif directive specifies the end of a conditional directive which began with the
#endif
#if directive.
#define The #define directive is used to define a symbol, which is a sequence of characters.
#warning The #warning directive is used to generate a CS1030 level one compiler warning
Preprocessor Directive Description
The symbols that are defined using the #define directive evaluate to true when used
#define TEST
using System;
namespace PreprocessorDirectivesDemo
class Example
{
{
#if (TEST)
#else
#endif
}
}