What do regions do in C#?

What do regions do in C#?

Regions in C# is a useful feature that helps manage code in areas that can be hidden or visible. Learn how to use regions in Visual Studio to improve code readability.

What is a code smell rails?

Code smells are symptoms of a deeper problem, and by eliminating them, we can leave our code elegant and odor free! Common code smells include long classes, large methods, dead code, and repetition. These issues are not only bad practice, but they indicate that there is probably a structural issue with our code.

How do you collapse a region in Visual Studio 2019?

You can also collapse an outlining region by double-clicking any line in the region on the outlining margin, which appears just to the left of the code. You can see the contents of a collapsed region as a tooltip when you hover over the collapsed region. This topic applies to Visual Studio on Windows.

Which is the best definition of an anti pattern?

An anti-pattern (or antipattern) is a pattern used in social or business operations or software engineering that may be commonly used but is ineffective and/or counterproductive in practice regions are anti-patterns.

Is it safe to use regions in StyleCop?

StyleCop SA1124 rule is clear: you should not use regions. Never. I’m currently doing a code review of my coworker’s code. The codebase contains a lot of regions, and is actually a perfect example of both how to not use regions and why regions lead to bad code.

When to use # region or # endregion in C #?

C# allows the use of #region / #endregion keywords to make areas of code collapsible in the editor. Whenever I do this though I do it to hide large chunks of code that could probably be refactored into other classes or methods. For example I have seen methods that contain 500 lines of code with 3 or 4 regions just to make it manageable.

When do you use regions to hide something?

Other people use regions to hide lots of similar entities. For example, when you have a class with hundred fields (which makes at least 500 lines of code if you count the comments and the whitespace), you may be tempted to put those fields inside a region, collapse it, and forget about them.