How do you recommend using #region / #endregion? To what extent should that replace using sub functions to clarify your code?
C# – #region/#endregion vs sub functions
cvisual studio
Related Topic
- C# – When should I use a struct rather than a class in C#
- C# – Proper use of the IDisposable interface
- C# – ‘Static readonly’ vs. ‘const’
- C# – reason for C#’s reuse of the variable in a foreach
- C# – Best practice to call ConfigureAwait for all server-side code
- C# – How and when to use ‘async’ and ‘await’
- Scala: list.flatten: no implicit argument matching parameter type (Any) = > Iterable[Any] was found
Best Answer
Not at all.
First of all,
#regions
are more a way of grouping many related functions/members into collapsible regions. They are not intended to structure a single multi-thousand line function into parts. (That being said, if you write a single method that's so long that you consider structuring it with#region
s then you're probably doing something seriously wrong. Regions or not, that code would be unmaintainable. Period.)Many people argue however, that it doesn't really help and that you should consider rewriting classes that actually need regions to be understandable. Also, regions tend to hide nasty code.