After maintaining lots of code littered with #region (in both C# and VB.NET), it seems to me that this construct is just a bunch of "make work" for the programmer. It's work to PUT the dang things into the code, and then they make searching and reading code very annoying.
What are the benefits? Why do coders go to the extra trouble to put this in their code.
Make me a believer!
Suggestions for Special Songs to Dedicate to Your Child:Baby Mine by Alison Krauss. Beautiful Boy by John Lennon (there is also a Celine Dion version) The Best Part of Me by Lee Price. Blessed by Elton John.
CoComelon was created in 2005 by Jay Jeon, a father of two in Southern California. Jeon, who had directed some TV commercials, was trying to teach his kids the ABCs. He started working with his wife, a children's-book author, to make videos to accompany the nursery rhymes they sang to their sons.
A similar question has already been asked.
but...
I would say not anymore. It was originally intended to hide generated code from WinForms in early versions of .NET. With partial classes the need seems to go away. IMHO it gets way overused now as an organizational construct and has no compiler value whatsoever. It's all for the IDE.
Often times, both partials and #regions are used as a crutch for bad design (e.g. class is too big or tries to do too many things).
The best use I've had for #regions so far is the grouping of functionality that is seen in many different classes. For example, value objects that have getters, setters, constructors and supporting fields. I might very well group those ideas into regions. Its a matter of opinion, however, as to whether that makes code cleaner or harder to read.
http://www.rauchy.net/regionerate/ - Automatically regionised your code ;)
I'm a fan of regions for grouping sections of large classes, say all the properties together, all constances, etc. I'm someone who's constantly collapsing code I don't need to see at that time so I love regions for that.
Also I find regions really useful when implementing interfaces, particularly multiple interfaces. I can group each interfaces methods, properties, events, etc so it's easier at a glance to see what method belongs to what interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With