Organize Your Code with Named Regions

 

Versions: 2005, 2008, 2010

Code: vstipEdit0095

 

 

Did you know you can create named Regions that can be used to organize your code? Let’s take a look at how to do it.

 

Creating Named Regions

C++

In C++ you create regions by using “#pragma region” with label and “#pragma endregion” (case-specific):

image

 

 

C#

For C# you can eliminate the “pragma” keyword and just use “#region” with label and “#endregion” (case-specific):

image

 

 

VB

Visual Basic is just as easy as C# and uses a similar syntax of “#Region” with label and “#End Region” (not case-specific):

image

 

 

 

Value of Named Regions

The value of creating Regions is twofold. First, they travel with the code so are shared by all team members when using source control. Second, they become part of document outlining and can be collapsed or expanded to further organize you code:

image