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