Information Technology Reference
In-Depth Information
Region Directives
The region directive allows you to mark, and optionally name, a section of code. The # region
directive
￿
Is placed on the line above the section of code you want to mark
￿
Can have an optional string of text following it on the line, which serves as its name
Must be terminated by an #endregion directive, farther down in the code
￿
Although region directives are ignored by the compiler, they can be used by source code
tools. Visual Studio, for example, allows you to easily hide or display regions.
As an example, the following code has a region called Constructors , which encloses the
two constructors of a class MyClass . In Visual Studio, you could collapse this region to a single
line when you didn't want to see it in the code, and then expand it again when you needed to
work on it or add another constructor.
#region Constructors
MyClass()
{ ... }
MyClass(string s)
{ ... }
#endregion
Regions can be nested, as shown in Figure 22-3.
Figure 22-3. Nested regions
Search WWH ::




Custom Search