Pre-compiling, also known as preprocessing, is the replacement of code text. Processing # At the beginning of the instructions, such as copy #include contained in the file code, #define宏定义的替换, conditional compilation, etc., is the preparatory work for the compilation of the stage, the main processing # start of the precompiled instructions.
The following is an introduction to the precompilation directives in C #:
1. #define和 #undef
Usage:
#define DEBUG
#undef DEBUG
#define告诉编译器, I define a debug symbol that resembles a variable, but it has no specific value and can look at it as a symbol. #undef就是删除这个符号的定义. If the symbol debug is not defined, then #undef does not work, otherwise #define does not work. Both must be placed before the source code. The order of the two looks at the order of the Code:
#define DEBUG
#undef DEBUG
In this case, debug is undefined, and if the two are in a different order, the compiler will assume that debug is defined
2. #if, #elif, #else, #endif
This tells the compiler to compile the code in Process Control. Consider the following code:
#if DEBUG
Console.Write("debug");
#elif RELEASE
Console.Write("realse");
#else
Console.Write("other");
#endif
The above code means that if debug is defined, the output is debug, the release is defined, the output is realse, otherwise the output is other. What happens if debug and realse are defined? You can try it yourself.
3. #warning, #error
These two designations let you tell the compiler whether to give a warning or an error message. The compilation will stop except for the error message.
Refer to the following code:
#if DEBUG ------〉该DEBUG如果选中当前状态为DEBUG,则这个默认为#define
#warning “现在是Ddbug状态”
#elif RELEASE ------〉如果选中release状态的话,这个确没有默认,不知道我试验的对不对
#warning “现在是Realse状态”
#else
#error“并清楚什么状态”
#endif
4. #region and #endregion
This two is used to make up a block of code.