Preprocessor Directives Compiler को Actual Compilation शुरू होने से पहले Information को Preprocess करने का Instruction देती हैं।
सभी Preprocessor Directives # से शुरू होती हैं, और एक Line पर Preprocessor Directive से पहले केवल White-Space Characters दिखाई दे सकते हैं। Preprocessor Directives Statements नहीं होतीं, इसलिए वे Semicolon (;) से End नहीं होतीं।
C# में कुछ Preprocessor Directives निम्न हैं:
| Sr.No | Preprocessor Directive & Description |
|---|---|
| 1 | #define यह Characters के Sequence को Define करता है, जिसे Symbol कहते हैं। |
| 2 | #undef यह आपको एक Symbol को Undefine करने की अनुमति देता है। |
| 3 | #if यह Test करने की अनुमति देता है कि Symbol या Symbols True Evaluate होते हैं या नहीं। |
| 4 | #else यह #if के साथ Compound Conditional Directive बनाने की अनुमति देता है। |
| 5 | #elif यह Compound Conditional Directive बनाने की अनुमति देता है। |
| 6 | #endif Conditional Directive के End को Specify करता है। |
| 7 | #line यह आपको Compiler के Line Number और (Optionally) File Name Output को Errors और Warnings के लिए Modify करने देता है। |
| 8 | #error यह आपके Code में Specific Location से Error Generate करने की अनुमति देता है। |
आइए #define Preprocessor का एक Example देखते हैं जो Characters के Sequence को Define करता है।
Example
#define PI using System; namespace PreprocessorDAppl { class Program { static void Main(string[] args) { #if (PI) Console.WriteLine("PI is defined"); #else Console.WriteLine("PI is not defined"); #endif Console.ReadKey(); } } }Output
PI is defined