Tuesday, April 10, 2007
Make Use of #regions When Developing C# .net Code - Coding Guidlines Series
The is part of a .net Coding Guidelines series of blog postings.
Making code readable is an important consideration when developing and maintaining code. The single best way to make code more organized, thus more readable, is to use "region" compiler directive. Regions effectively group your code into sections and chapters.
This is a simple example of code without the region directive. The code is all there but even with just a few lines it can be difficult to read because nothing stands out. This only gets worse when the class is hundreds or thousands lines long.
Here is the same code with regions. It just looks a lot cleaner.
Now when you have found the selection that you want it is simply a matter of double clicking the region tag to see the details.
(example to be added)Even code with regions can get out hand when there are a large number of regions. Then it is time to group the regions into regions.
Making code readable is an important consideration when developing and maintaining code. The single best way to make code more organized, thus more readable, is to use "region" compiler directive. Regions effectively group your code into sections and chapters.
(example to be added)Even code with regions can get out hand when there are a large number of regions. Then it is time to group the regions into regions.
Labels: C Sharp, CodingGuideline C#, Visual Studio
Comments:
<< Home
You could reorganize the code so that one things are at top, some at middle, and some at bottom and then leave some space between methods and group all attributes and not put attributes above getters. Would be easier to read without regions.
I LOVE using regions. Along with regions are the keystrokes CTRL+M + M, L, O, P, they are invaluable!
Post a Comment
<< Home
Subscribe to Posts [Atom]

