C # region directive

Source: Internet
Author: User

Region directive

Sometimes, to complete a requirement, you might write dozens of lines, hundreds of lines, or even thousands of lines of code.

When the number of code is very large, although you can use very detailed comments to help read, but it is not easy to understand what the code is doing things.

As a result, C # adds a syntax format--region, which is written in the following way:

#region 描述内容
// 代码
#endregion

Region and Endregion must be written in pairs, that is, you cannot write only one region or only one endregion, and they all start with a # number.

What good does it do? Once you've written this, you can fold the code between them, like this:

In this way, for a large segment of the code, you can use this method of folding up, making the entire code easier to read.

As with comments, the region directive and the Endregion directive do not participate in compilation.

In other words, in the compiler generated EXE file, there is no such instruction, it exists only in the source code, easy to read.

Console Clear Screen

Sometimes, when the program runs to some point, we need to clear the current contents of the console, this time, we need to use the console to clear the screen command.

This command is simple and can be used with the following code:

//当程序运行到这条语句时,控制台当前的内容会被清空

For example:

Console.Write("Hello");
Console.Clear(); //当程序运行到这条语句时,控制台当前的内容会被清空
Console.Write("World");

After running, you can only see the world, because although the output of Hello, but encountered the console clear screen command, the output of the content removed.

C # region directive

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.