Pre-Processor Conditional Directives

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:Tutorials
C# Tutorials
C# Preprocessor Directives
edit

Basic Usage

The most often used of directives are:-

  • #define
  • #if
  • #endif

The #define directive allows you to define a pre-processor variable, this is pretty useless on its own, but used in conjunction with the #if and #endif directives it allows you to compile code depending on if a variable has been defined. Visual studio greys out code that will not be compiled.

Example 1

Image:conditionalpp1.gif


Example 2

Image:conditionalpp2.gif

Notice the grey line of code on line 14; this will not be executed as it is not compiled


Personal tools