The C# Preprocessor Directives

So what are preprocessor Directives?? They are symbols used in C# language to help us to interact with the compilation process. The basic C# preprocessor symbols we use are ::

  • #define,#unDef
  • #if,#elif,#else,#endif
  • #line
  • #error,#warning
  • #region,#endregion

I hope many people are familiar with the #region and #endregion.They are the directive used to make our lengthy codes more manageable .Using this directive we can specify a specific block of code in our .cs file and make that block distinct.

The conditional preprocessor directives #if,#elif,#else,#endif are mainly used to conditionally compile our code .The best example will be if we want to execute a set of code when our code is running under debug mode we make use of the conditional directive .
For Example,
#if(DEBUG)
some C# code
#endif
Here the C# code written inside the directives will be compiling into the assembly only when the code is compiled in the debug mode.

The #define directive is used to define some C# symbol .For example if we want to define the DEBUG symbol in our code we use the code #define DEBUG. The only important thing to note is that we should use the define directive only at the top of the code or before anything we write in the .cs file .

The #warning and #error directives are used for showing some messages after the compilation of the code is being done .Along with other errors or warnings (if any) our directed messages are shown .

The Last directive #line is used to alter the line number sequence in our code. This can be checked only when we use the line numbers our code page. We can use the #line default to make the line numbers back in track at the time of compilation.

3 thoughts on “The C# Preprocessor Directives

  1. noreply@blogger.com (dewwy peterson)

    This is a great blog you have here… what a great place to share information. Hope you don’t mind I paid you a visit. I also have a site about rashguards because I like to surf.

    bye bye – thanks for having this blog! (if you want, come visit my blog – I’m always looking for suggestions)

  2. noreply@blogger.com (job opportunitya)

    Fruitful blog. I favor your site and I shall
    return to it! I go to sites like this when I get the
    chance, and find blog just like this.
    Hey why don’t you peep my Solution Provides blog site.

Leave a Reply

Your email address will not be published. Required fields are marked *