C# – Compiler preprocessor directive


  • This directive uses to assign the symbol. It may used with conditional directive to evaluate the code. It should be handled carefully and removed before release.



Example: #define DEBUG

  • Conditional directive





Example: #if (DEBUG)

  • Compiler Error and warning directive are using to assign error and warning message to compiler respectively. Also it should be handled carefully.



Example: #error Debug defined

  • This line directive is using force to define into specific line number instead of actual line number.


Example: #line 200 // Actual line number of this line in the coding block is 20

               #line default

  • This region and endregion directive are often used by the developer to segregate code into similar functionalities. Also useful to collapse and expand the code block.



Example: #region ConvertToXMLFormat

               #endregion ConvertToXMLFormat

  • Directive to instruct the compiler for support special instruction.


#pragma warning

#pragma checksum

Example: #pragma warning disable 169, 414

               #pragma checksum "file.cs" "{3673e4ca-6098-4ec1-890f-8fceb2a794a2}" "{012345678AB}"


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s