C # and C + + code folding features __c++

Source: Internet
Author: User
Recently wrote the program, encountered a very worried about the problem is when the code reached a certain scale, the code will become very disordered, neither convenient to read, nor convenient debugging, more inconvenient to check the wrong. One thing to emphasize is that if you write your code in a lot of processes or methods, the VS IDE can fold or expand each process or method to some extent to ease code confusion, but this happens when your program reaches a certain size. That is in one of the methods also have a long code, this time without the code folding and expansion function, do you feel very uncomfortable? Anyway, that's what I think. (In this case, the developers of Microsoft's VS team are not thinking about this, after all, people write programs that are much larger than most of us have written, and fortunately, Microsoft has already provided the solution, and of course you can select a piece of code in the VS IDE and press the shortcut key ctrl+m+ H can collapse the selected code, but this folding method will not be saved, and when you exit the IDE and re-enter the project, the last code collapse is gone. So is there a way to save the folding effect? The answer is yes. In C # (here's to say, C # is from. NET, so as long as it is based on. NET language, such as asp,asp.net, etc.), we can use #region          #endregion     keyword to declare a section of code. Eg: #region   parameter definition int A; ... #endregion you will be surprised to find that the #region        #endregion间的代码段已经可以折叠或是展开了, and is permanently valid. In addition, #region是可以嵌套的, the usage is the same as the {} usage in the c,c++ language, such as: #region   parameter definition #region   integer parameter int A; ... #endregion #region   string name; ... #endregion ... #endregion   in C + +, such a function can also be implemented, but the usage is slightly different, in C + + can use #pragma region  #pragma Endregion keywords to achieve the same functions as: #pragma region variable declaration  int i;
#pragma endregion variable declaration this keyword can also be nested, no longer detailed examples here, the reader can refer to C # usage. Note the difference between C + + and C # usage in addition, the above method is only the VS IDE compiler can recognize, the special C + + language, do not compile code that exists code partition with other compilers, otherwise the compiler will appear unrecognized #pragma, #region等关键字的情况, and, A similar situation may exist in a lower version of the VS IDE, but it is certain that the version after VS 2005 will be recognizable.

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.