A Primer to Preprocessing Directives

Use the Visual Studio feature to comment out blocks of code while evolving the code at development time. If you find yourself doing this quite often (for example, to enable or disable some diagnostic code), you’re likely better off with conditional compilation using an #if preprocessing directive. We won’t detail the preprocessing capabilities (which is really a misnomer in the world of C# because there’s no separate preprocessor stage in compilation) right now, but here’s the crux of it.

Using the #define directive, a symbol can be defined for further use in conditional preprocessing directives like #if. Blocks of code surrounded by #if and #endif are conditionally included in the source code analyzed by ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.