Tuesday, December 22, 2009

C#.NET Coding Standards

Naming Conventions and Standards:
1. Use Pascal casing for Class names.
Pascal Casing - First character of all words are Upper Case and other characters are lower case. Example: SalahuddinAhmedBlog
2. Use Pascal casing for Method names.
3. Use Camel casing for variables and method parameters.
Camel Casing - First character of all words, except the first word are Upper Case and other characters are lower case. Example: salahuddinAhmedBlog
4. Use the prefix “I” with Camel Casing for interfaces.
5. Use Meaningful, descriptive words to name variables. Do not use abbreviations.
6. Do not use single character variable names like i, n, s etc. Use names like index, temp.
One exception in this case would be variables used for iterations in loops.
7. Do not use underscores (_) for local variable names.
8. All member variables must be prefixed with underscore (_) so that they can be identified from other local variables.
9. Do not use variable names that resemble keywords.
10. Prefix boolean variables, properties and methods with “is” or similar prefixes.

Indentation and Spacing:
1. Use TAB for indentation. Do not use SPACES. Define the Tab size as 4.
2. Comments should be in the same level as the code (use the same level of indentation).
3. Curly braces should be in the same level as the code outside the braces.
4. Use one blank line to separate logical groups of code.
5. There should be one and only one single blank line between each method inside the class.
6. The curly braces should be on a separate line and not in the same line as if, for etc.
7. Use a single space before and after each operator and brackets.
8. Use #region to group related pieces of code together.
9. Keep private member variables, properties and methods in the top of the file and public members in the bottom.

No comments:

Post a Comment

Related Posts with Thumbnails