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.

No comments:
Post a Comment