CSharp (C#) language _C# "preprocessing instructions"

What are preprocessing directives

  The definition of the source code specifies a program, preprocessing directive (preprocessor directive) indicating how the source code compiler.
  For example, in some cases, we may want the compiler to ignore part of the code, and in other cases, we may want the code to be compiled. The preprocessing directive gives us such options. There is an actual preprocessing stage
  in C and C++ . At this time, the preprocessing program traverses the source code and prepares the text output stream for the subsequent compilation stage . There is no actual preprocessing program in C# . " Preprocessing " directives are processed by the compiler, and the term is retained

basic rules

  • The preprocessing directive must be on a different line from the C# code
  • Unlike C# statements, preprocessing instructions do not need to end with a semicolon
  • Each line containing preprocessing directives must start with the # character
    • There can be spaces before the # character
    • There can be a space between the # character and the instruction
  • Allow end-of-line comments
  • Delimiter comments are not allowed on the line where the preprocessing directive is located
//                结尾没有分号
#define PremiumVersion 	// 正确

// 前面的空格
  #define BudgetVersion // 正确

// 中间有空格
# define MediumVersion  // 正确

//							 不允许分隔符注释
#define PremiumVersion  /* all bells & whistles */

// 								行尾注释可以
#define BudgetVersion 	// Stripped-down version

Preprocessing directive

instruction Meaning summary
#define identifler Define compiler
#undef identifier Undefine compiler
#if expression If the expression is true, compile the following fragment
#elif expression If the expression is true, compile the following fragment
#else If the previous #if or #elif expression is false, compile the following fragment
#endif Mark the end of an #if structure
#region name Mark the beginning of a piece of code, no compilation effect
#endregion name Mark the end of a piece of code, no compilation effect
#warning message Display warning messages during compilation
#error message Display error messages during compilation
#line indicator Modify the number of lines displayed in the compiler message
#pragma text Specify information about the program context

Guess you like

Origin blog.csdn.net/qq_43562262/article/details/107998087