Guide to the Language
CHAPTER 25 Preprocessors
Download 2 Mb. Pdf ko'rish
|
C sharp
- Bu sahifa navigatsiya:
- Directive Description
- Preprocessor Syntax
- Conditional Compilation Symbols
- Conditional Compilation
CHAPTER 25
Preprocessors C# includes a set of preprocessor directives that are mainly used for conditional compilation. Although the C# compiler does not have a separate preprocessor, as C and C++ compilers, the directives shown here are processed as if there were one. That is, they appear to be processed before the actual compilation takes place. Directive Description #if #elif #else #endif If Else if Else End if #define #undef Symbol define Symbol undefine #error #warning #line Generate error Generate warning Set line number #region #endregion Mark section start Mark section end 142 Preprocessor Syntax The preprocessor directives are easily distinguished from normal programming code in that they start with a hash sign (#). They must always occupy a line that is separate from anything else, except for single-line comments. Whitespace may optionally be included before and after the hash mark. #line 1 // set line number Conditional Compilation Symbols A conditional compilation symbol is created using the #define directive followed by the symbol’s name. When a symbol is defined, it will then cause a conditional expression using that condition to be evaluated as true. The symbol will remain defined only within the current source file, starting from the line where the symbol is created. #define MySymbol The #undef (undefine) directive can disable a previously defined symbol. #undef MySymbol Conditional Compilation The #if and #endif directives specify a section of code that will be included or excluded based on a given condition. Most often, this condition will be a conditional compilation symbol. #if MySymbol // ... #endif ChaptEr 25 prEproCESSorS 143 Just as with the C# if statement, the #if directive can optionally include any number of #elif (else if) directives and one final #else directive. Conditional directives may also be nested within another conditional section. In longer conditionals, it is good practice to add comments to the #endif directives to help keep track of which #if directive they correspond to. #if Professional // ... #elif Advanced || Enterprise // ... #else #if Debug // ... #endif // Debug #endif // Professional Download 2 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling