Region Placement (+.5 VB.Net)

I love regions.  I use them to categorize my class in a way that makes it very quick and easy to find what I am looking for.  Visual Studio 2005 handles regions differently in VB.Net and C#.

The first VB.Net advantage is that regions are left aligned rather than being tabbed alongside code, and are colored differently.  This makes them easier to spot and does not clutter the code as much.




The second VB.Net advantage is that it will automatically create the end keyword for a region.  This is just another example of VB.Net automatically finishing blocks, and is covered elsewhere.


#region “Properties”


#Region “Properties”
#End Region


#region “Properties”


2 comments so far

  1. hobbit on

    1) having regions left-aligned or code-aligned is a matter of taste. Personally I can’t stand the way. It disrupts the natural tab-flow (in c# convention the tab distance will always flow smoothly (you are never jumping back 8 tabs between lines)

    2) Saying that the c# way “clutters up the code more” is also a matter of opinion.

    3) Having regions automatically close is only an advantage if you are writing the region code *ahead of time* (i.e. when you have no existing code that should go i the region) Otherwise it is a disadvantage. Now I have to cut out the auto-inserted one and move it to where it actually needs to go.

  2. Jon_w on

    (more similar comments in Block Completion comment section)

    Again this problem also can be solved with codesnippets 😀

    #Region+TAB (Enter region name)+ENTER
    creates end block and indentaion inside of region.

    @hobbit – comment

    You could use the “surrond with” if you already have existing code.

    * Select code
    * Right click (“context-click”)
    select surround with : region

    Don’t like to use the mouse?
    CTRL + K + X (or your codesnippet trigger combo)
    select c# : region

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: