C # Preprocessor commands

Source: Internet
Author: User

At the very beginning of contact with pre-processing directives, #region and #endregion are used to collapse blocks of code for easy viewing. Using it can be subordinate to a small module of the content put together, folded up, only when viewing the time to open again, obsessive-compulsive disorder should be very fond of. The book just turned to this, put this part of the record down, give yourself a wake up.

Preprocessor directives do not translate into executable code, but rather affect the code's compilation process, optionally compiled, and there is a conditional compilation concept. As I understand it, the preprocessor command does not exist after the executable is generated, and it affects the process of generating the executable, which tells the compiler which code needs to be compiled and which code is not required. It does not modify the functionality of the code, but it can specify which part of the code to compile in the compilation phase, that is, what functionality is in the resulting executable file. Its role is embodied at compile time.

    1. #define和 #undef: The function is to tell the compiler that there is a variable of the given name, which is equivalent to the normal variable definition and can be compiled with other commands.
    2. #if, #elif, #else, #endif: By judging the variables defined by # define, there is a selective compilation of code blocks to achieve the purpose of conditional compilation
    3. #warning和 #error: You can use these two instructions to determine whether the preprocessor command is writing correctly, there is no logic error, warning can also remind you to perform an action.
    4. #region和 #endregion: Definition: A block that marks a piece of code as having a given name, which can be recognized by some editors for better layout. As far as I am concerned, it is used to collapse blocks of code. #
    5. #line: Change the file name and line number information that the compiler displays in warning and error messages
    6. #pragma: Suppresses or restores the specified compilation warning

In general, the three-way bar can be used to achieve conditional compilation. 4 folding code block, 56 for the moment, I don't see how much it works.

C # can not only use preprocessing commands to complete conditional compilation, but C # can also be implemented through the conditional feature, which is now more of a trend.

C # Preprocessor commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.