Preprocessor Directives

Preprocessor directives are instructions to the C# compiler to perform some action during compilation. There is no equivalent functionality in Java. The term preprocessor directive is misleading because the compilation process does not include a preprocessing step, but the term is a legacy of C/C++ and has remained to avoid confusion.

Preprocessor directives are used to

  • Conditionally include and exclude sections of code during compilation.

  • Force the compiler to issue warnings and errors.

  • Group related sections of source code.

  • Alter the line number and file-name references displayed by the compiler for errors and warnings.

Preprocessor directives are preceded by the # symbol and must be the only command on a line. They are not ...

Get C# for Java Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.