Preprocessor Directives

In some programming languages, such as C++, the preprocessing stage is a separate process from compilation. This stage happens before the actual process of compilation. The following are some of the areas where preprocessing is useful:

  • Conditional compilation

  • Header files inclusion

  • Macro expansion

However, in C#, the only area where preprocessing is used for conditional inclusion and exclusion of code. Also, in C#, the compiler itself emulates the preprocessor.

A preprocessor directive is a special command that begins with the # symbol.

The preprocessor directives provided in C# are

  • #define

  • #undef

  • #if

  • #else

  • #elif

  • #endif

  • #warning

  • #error

  • #line

  • #region

  • #endregion

The following sections discuss each of these preprocessor directives in ...

Get Special Edition Using C# 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.