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.

Labels: , ,


Comments:
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!
 
Good for people to know.
 
Nice brief and this enter helped me alot in my college assignement. Gratefulness you as your information.
 
Post a Comment





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]