Preprocessor directives are typically used to make source programs easy to change and easy to compile in different execution environments. Directives in the source file tell the preprocessor to perform specific actions. For example, the preprocessor can replace tokens in the text, insert the contents of other files into the source file, or suppress compilation of part of the file by removing sections of text. Preprocessor lines are recognized and carried out before macro expansion. Therefore, if a macro expands into something that looks like a preprocessor command, that command is not recognized by the preprocessor.
Preprocessor statements use the same character set as source file statements, with the exception that escape sequences are not supported. The character set used in preprocessor statements is the same as the execution character set. The preprocessor also recognizes negative character values.
Conditional expressions (
#elif, etc) do support a limited subset of boolean operators. They are:
!=. These can only be used for testing whether the symbol is true (defined) or false (not defined)
#if !DEBUG && (SOME_SYMBOL || SOME_OTHER_SYMBOL) && RELEASE == true Console.WriteLine("OK!"); #endif
would compile code that prints "OK!" to the console if
DEBUG is not defined, either
SOME_OTHER_SYMBOL is defined, and
RELEASE is defined.
Note: These substitutions are done at compile time and are therefore not available for inspection at run time. Code eliminated through use of
#if is not part of the compiler's output.
See Also: C# Preprocessor Directives at MSDN.