In C#
#Region "Don't Touch This!" ... #EndRegion
In VB.Net
#Region "Don't Touch This!" ... #End Region
So in essence, there’s not much of a difference apart from the space in between End and Region
You can’t use a Region or an End Region inside a function or subroutine. In other words, this doesn’t work:
Public Sub ThisSub() #Region "Don't Touch This!" ' The code for this subroutine #End Region End Sub
That’s OK … Visual Studio will collapse subroutines without a Region directive. If you ever find yourself the need to put #Region inside a subroutine/function, it usually means that the subroutine/function is getting a bit big and it’s time to refactor (modularize) it.
But you can nest Regions. In other words, this does work:
#Region "Outer Region" Public Class FirstClass ' Code for FirstClass End Class #Region "Inner Region" Public Class SecondClass 'Code for SecondClass End Class #End Region #End Region
Leave a Reply