I have see alot of old code and from a lot of developers.
#region #endregion
can be helpful some times but if is use well.
how is the best way to use it to keep my code organized and easy to read?
I have see alot of old code and from a lot of developers.
#region #endregion
can be helpful some times but if is use well.
how is the best way to use it to keep my code organized and easy to read?
It doesn't mean anything special if that's what you're asking. The only special effect it has is within Visual Studio for code folding.
If you have a large class that performs a few tasks, it may be best to region it out by separating your properties, different groups of methods, interface implementations, and whatever else you think may be important. There are no strict rules.
class MyReallyBigClass : IAwesome, INotAsAwesome
{
#region Public Properties
public string Test { get; set; }
// ..
#endregion
#region IAwesome Implementation
public void IAwesome.BeAwesome()
{
// ..
}
public int IAwesome.AwesomeLevel()
{
// ..
}
#endregion
#region INotAsAwesome Implementation [[...]]
#region Internal Fields
private int _whatever;
// ..
#endregion
}
Of course in practice, you wouldn't really get a class so large that you'd need to separate it out, but I normally do find myself using it around properties and interface implementations at the least.
It's purely to aid readability in the IDE. It's effectively stripped out on compilation.
That said, I tend to defer to Microsoft's style guidelines with regards to usage: grouping methods, properties, constructors, etc. - rarely, if ever, inside a method, and never between a brace construct (if, for, etc) and the opening brace.