10
What are the advantages and disadvantages of using #regions
in the C#
?
Its use really facilitates code organization?
#region
/* Código */
#endregion
10
What are the advantages and disadvantages of using #regions
in the C#
?
Its use really facilitates code organization?
#region
/* Código */
#endregion
13
It is irrefutable that the religions facilitate the organization, but one should take some care with what really you intend to organize.
I recommend using them when considering the following purposes:
I believe the use of religions to separate members of a class according to levels of protection (private, public, etc.) is justifiable, but I define its use as preferential because, while sometimes the best thing to do is to group them according to their functionality, in others it becomes more feasible to organize them based on the own needs of its application.
Now, use religions to hide "ugly" code is reprehensible; when the intention is to hide, why not avoid future confusions and spend a small part of the time in refactoring certain functionality?
4
His idea is to decrease the amount of code displayed on the screen by grouping common functions. The advantage is to keep the code more succinct for reading.
The downside is that the religions hide the signatures of the methods. When it is important to see the signatures of each method, the shortcut Ctrl + M, Ctrl + The Is more useful.
I usually use #Region and Ctrl+M and Ctrl+O in sets. Create for example a sea of Fields and Properties, then I use #Region Fields to isolate my Fields and #Region Properties to isolate the properties... #Region Constructor and so on... then I use Ctrl+M to reduce all methods tbm... with this I consider that I have a gain of organization, because then I know clearly where to go... for example if I have to touch a Property, I go right there in Gion and Property, when I can’t remember her name to use the navigation shortcuts
Also use, but #Region use less.
3
This is just a way to organize the code, and is usually used by generated code.
In codes not generated I recommend a certain care when using Codes, because when used to separate codes according to some sort of classification, they tend to become outdated.
The use I recommend, is to group members that have some real connection. For example:
Browser other questions tagged c#
You are not signed in. Login or sign up in order to post.
+1 for condemning relics to hide ugly parts of the code. = D There are people who do just that, hehe!
– Miguel Angelo
+1 for the same reason as @Miguelangelo
– Tafarel Chicotti
There is way to do this in Javascript ?
– Matheus Miranda