Region in VB.NET

Region directive is useful when you have lot of code and you need to add formatting to it. This article demonstrates how to use the Region directive in Visual Basic .NET.
  • 14864

Region directive is useful when you have lot of code and you need to add formatting to it.  This article demonstrates how to use the Region directive in Visual Basic .NET.

Region directive in VB.NET is used to provide formatting of code. It helps you to build region areas where you can comment your code and then show or hide that entire area/region by using expand and collapse options.

The #Region directive followed by a region name string and ends by #End Region is used to create a region.

The following code snippet uses #Region and #End Region.

Module Module1

 

#Region "Main Region"

 

    Sub Main()

        ' Write some code here

    End Sub

 

#End Region

 

 

#Region "Other Region"

    ' Some code goes here

 

#End Region

 

 

End Module

 

Here is my code looks like in Visual Studio 2008.

RegionImg1.gif
 

Now I can simply collapse and expand regions. Here is my code looks like when collapsed in Visual Studio 2008.

 RegionImg2.gif


 


  

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.