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.
VB.Net:
C#:
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.
Type:
#region “Properties”
VB.Net:
#Region “Properties”
#End Region
C#:
#region “Properties”
1) having regions left-aligned or code-aligned is a matter of taste. Personally I can’t stand the vb.net 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.
(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.
How?
* 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
TADA!