C# program that uses region directives
static void Main()
Console.WriteLine("How are you today?");
How are you today?
Example screenshot. In the code example, we see the complete program. In the screenshot, we see the code in Visual Studio environment with the #region areas collapsed.
Tip: To collapse a region, click the plus-minus sign on the left margin of Visual Studio next to your code.
A discussion. Region is not ideal. Consider instead using more classes and scopes. This enables compile-time detection of problems. It helps use the full capabilities of the C# language.
A summary. The #region directive operates at the level of the text. It does not require any particular scope to be balanced in the file. Regions do not affect the final compiled metadata.