Preprocessor Directives

The last topic discussed in this chapter is using preprocessor directives. These are directives to the compiler, not C# statements, and they enable you to skip compilation of sections of your code that you specify.

Here are the C# preprocessing directives:

  • #define and #undef are used to define and undefine, respectively, conditional compilation symbols.

  • #if, #elif, #else, and #endif are used to conditionally skip sections of source code.

  • #error and #warning are used to display errors and warnings, respectively.

  • #region and #endregion are used to mark sections of source code.

  • #line is used to control line numbers for errors and warnings.

You can see an example in ch01_12.cs, Listing 1.12. In that example, it's the user's birthday, ...

Get Microsoft® Visual C#® .NET 2003 Kick Start 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.