Introduction
This is a general Code Review checklist and guidelines for C# Developers, that will serve as a reference point during development. This is to ensure that most of the general coding guidelines have been taken care of, while coding. Especially, it will be very helpful for entry-level and less experienced developers (0 to 3 years experience) as a reference checklist until it becomes a habitual practice for them.
Article Reference
Previously, I have posted this article on CodeProject.com, you can have a look at it here:
http://www.codeproject.com/Articles/593751/Code-Review-Checklist-and-Guidelines-for-Csharp-De
Checklist
- Ensure that there shouldn't be any project warnings.
- It will be much better if Code Analysis is performed on a project (with all Microsoft Rules enabled) and then remove the warnings.
- All unused usings need to be removed. Code cleanup for unnecessary code is always a good practice.
Refer to: http://msdn.microsoft.com/en-us/magazine/ee335722.aspx.
- A "null" check needs to be performed wherever applicable to avoid the Null Reference Exception at runtime.
- Naming conventions are to be followed always. Generally for variables/parameters, follow Camel casing and for method names and class names, follow Pascal casing.
Refer to: http://msdn.microsoft.com/en-us/library/ms229043.aspx.
- Ensure that you are aware of SOLID principles.
Definition from Wikipedia: In computer programming, SOLID (Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion) is a mnemonic acronym introduced by Michael Feathers for the "first five principles" identified by Robert C. Martin in the early 2000s that stands for five basic principles of object-oriented programming and design. The principles when applied together intend to make it more likely that a programmer will create a system that is easy to maintain and extend over time. The principles of SOLID are guidelines that can be applied while working on software to remove code smells by causing the programmer to refactor the software's source code until it is both legible and extensible. It is typically used with test-driven development, and is part of an overall strategy of agile and adaptive programming.
Refer to: http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
- Code Reusability: Extract a method if the same piece of code is being used more than once or you expect it to be used in the future. Make some generic methods for repetitive tasks and put them in a related class so that other developers start using them once you intimate them. Develop user controls for common functionality so that they can be reused across the project.
Refer to:
o http://msdn.microsoft.com/en-us/library/office/aa140806(v=office.10).aspx
o http://blogs.msdn.com/b/frice/archive/2004/06/11/153709.aspx
- Code Consistency: Let's say that an Int32 type is coded as an int and a String type is coded as a string, then they should be coded in that same fashion across the application. But not like sometimes an int and sometimes as an Int32.
- Code Readability: Should be maintained so that other developers easily understand your code.
Refer to: http://msdn.microsoft.com/en-IN/library/aa291591(v=vs.100).aspx
- Disposing of Unmanaged Resources like File I/O, Network resources, etcetera. They must be disposed of once their usage is completed. Use using blocks for unmanaged code, if you want to automatically handle the disposing of objects once they are out of scope.
Refer to: http://msdn.microsoft.com/en-us/library/498928w2.aspx
- Proper implementation of Exception Handling (try/catch and finally blocks) and logging of exceptions.
Refer to: http://msdn.microsoft.com/en-us/library/vstudio/ms229005(v=vs.100).aspx
- Ensuring that methods have fewer lines of code. Not more than 30 to 40 lines.
- Timely check-in/check-out of files/pages at source control (like TFS).
Refer to: http://www.codeproject.com/Tips/593014/Steps-Check-in-Check-Out-Mechanism-for-TFS-To-avoi
- Peer code reviews. Swap your code files/pages with your colleagues to perform internal code reviews.
- Unit Testing. Write developer test cases and perform unit testing to ensure that a basic level of testing is done before it goes to QA testing.
Refer to: http://msdn.microsoft.com/en-us/magazine/cc163665.aspx
- Avoid nested for/foreach loops and nested if conditions as much as possible.
- Use anonymous types if code is going to be used only once.
Refer to: http://msdn.microsoft.com/en-us/library/vstudio/bb397696.aspx
- Try using LINQ queries and Lambda expressions to improve readability.
Refer to: http://msdn.microsoft.com/en-us/library/bb308959.aspx
- Proper usage of var, object, and dynamic keywords. They have some similarities that cause confusion for developers or don't know much about them and hence they use them interchangeably, which shouldn't be the case.
Refer to: http://blogs.msdn.com/b/csharpfaq/archive/2010/01/25/what-is-the-difference-between-dynamic-and-object-keywords.aspx
- Use access specifiers (private, public, protected, internal, protected internal) as per the scope need of a method, a class, or a variable. Let's say if a class is meant to be used only within the assembly, then it is enough to mark the class as internal only.
Refer to: http://msdn.microsoft.com/en-us/library/kktasw36.aspx
- Use interfaces wherever needed to maintain decoupling. Some design patterns came into existence due to the usage of interfaces.
Refer to: http://msdn.microsoft.com/en-IN/library/3b5b8ezk(v=vs.100).aspx
- Mark a class as sealed or static or abstract as per its usage and your requirements.
Refer to: http://msdn.microsoft.com/en-us/library/ms173150(v=vs.100).aspx
- Use a Stringbuilder instead of string if multiple concatenations are required, to save heap memory.
- Check whether any unreachable code exists and modify the code if it exists.
- Write comments on top of all methods to describe their usage and expected input types and return type information.
- Use a tool like Silverlight Spy to check and manipulate rendered XAML in Runtime of a Silverlight application to improve productivity. This saves a lot of back & forth time between Design & Run views of the XAML.
- Use the fiddler tool to check the HTTP/network traffic and bandwidth information to trace the performance of web applications and services.
- Use the WCFTestClient.exe tool if you want to verify the service methods out of the Visual Studio or by attaching its process to Visual Studio for debugging purposes.
- Use constants and readonly wherever applicable.
Refer to:
o http://msdn.microsoft.com/en-us/library/acdd6hb7(v=vs.100).aspx
o http://msdn.microsoft.com/en-us/library/e6w8fe1b(v=vs.100).aspx
- Avoid type casting and type conversions as much as possible; because it is a performance penalty.
Refer to: http://msdn.microsoft.com/en-us/library/ms173105.aspx
- Override ToString (from Object class) method for the types that you want to provide with custom information.
Refer to: http://msdn.microsoft.com/en-us/library/ms173154(v=vs.100).aspx
- Avoid direct copying/pasting of code from other sources. It is always recommended to hand write the code even though you are referring to the code from some sources. By this, you will get good practice of writing the code yourself and also you will understand the proper usage of that code; finally you will never forget it.
- Always make it a practice to read books/articles, upgrade and follow the Best Practices and Guidelines by industry experts like Microsoft experts and well-known authors like Martin Fowler, Kent Beck, Jeffrey Ritcher, Ward Cunningham, Scott Hanselman, Scott Guthrie, Donald E Knuth.
- Verify whether your code has any memory leakages. If yes, ensure that they have been fixed.
Refer to: http://blogs.msdn.com/b/davidklinems/archive/2005/11/16/493580.aspx
- Try attending technical seminars by experts to be in touch with the latest software trends and technologies and best practices.
- Understand thoroughly OOP concepts and try implementing it in your code.
- Get to learn your project design and architecture to better understand the flow of your application as a whole.
- Take necessary steps to block and avoid any cross scripting attacks, SQL injection, and other security holes.
- Always encrypt (using good encryption algorithms) secret/sensitive information like passwords when saving to the database and in connection strings stored in web.config file(s) to avoid manipulation by unauthorized users.
- Avoid using the default keyword for the known types (primitive types) like int, decimal, bool, etcetera. It should usually be used with Generic types (T) since we may not be sure whether the type is a value type or reference type.
Refer to: http://msdn.microsoft.com/en-us/library/xwth0h0d(v=vs.100).aspx
Another Article Reference on Review Guidelines
Today, I came across another article related to Code review guidelines on CodeProject and I find it very interesting. The author has given a perfect explanation about what a code review is and what needs to be taken care of being a developer or being a reviewer, the importance of code reviews, tips for developers and reviewers, and review checklist. I recommend my readers to go through it once.
Article link: http://www.codeproject.com/Articles/524235/Codeplusreviewplusguidelines
Conclusion
I welcome feedbacks, queries, and suggestions from the readers so that I can improve it further and developers should get some benefit out of it. My aim is to gradually make it a complete code review guideline especially for C# developers and in the next version, I'm planning to add supporting code examples and screenshots for a much better understanding.
Disclaimer: This document does not guarantee that all the mentioned guidelines and practices are applicable as of today. Therefore it is always recommended to check MSDN, discuss with experts and check other portals for the current and modified guidelines and practices. Also, note that some of the provided reference links might not work.

Mohammed HameedPosted Aug 19, 2013, 7:38 AM
Thank you Ruchi.
Ruchi HPosted Jul 29, 2013, 8:21 AM
Nice Article
Sam HobbsPosted Jun 12, 2013, 4:23 PM
I think you understand very well. I think you will make substantial improvements to an already excellent article.
Mohammed HameedPosted Jun 12, 2013, 4:03 PM
Sam, could you please shed some more light on my replies to your comments so that I can finalize what changes/additions I must do in my article and update it accordingly. Thanks a lot in advance.
Sam HobbsPosted Jun 12, 2013, 4:01 PM
Note Mohammed that I an editor for this web site. I edited your article. I hope the edits are good. There was one item that was empty so I deleted that. I hope that is okay. So that affected the numbers and caused some of the numbers to change.
Mohammed HameedPosted Jun 12, 2013, 3:53 PM
Sam please, don't apologize. It is my pleasure and I'm feeling happier and honoured that an expert like you have gone through my article and has shed a light to improve it further by providing his invaluable suggestions & comments. And if God permits me I will take those suggestions seriously and will surely update the article. I think I must say a million times THANKS for your valuable time spent going through my article and giving feedbacks for overall improvements and therefore helping the Developer community. Thanks again.
Sam HobbsPosted Jun 12, 2013, 2:21 PM
I apologize for disagreeing, but in response to #15 about nested loops, If the requirements are complex enough then avoiding nested loops can make code more difficult to understand.
Sam HobbsPosted Jun 12, 2013, 1:30 PM
I think that #24 about unreachable code should be clarified. Classes are often developed with functions that are not used but that will be useful. The methods should not be removed just because they are not used. For some employers/clients it might be appropriate to comment out unreachable code. I think it is better to always attempt to determine why code is unreachable before removing it.
Sam HobbsPosted Jun 12, 2013, 1:21 PM
An example of a convention that is a matter of preference is camel case. It is not universally accepted. Some developers do not like it. I think it should be stated and emphasized in this article that if a program is developed using some other convention, then that convention should be maintained unless the owner (the employer or client) specifies otherwise. Something else that should be emphasized is #12 about lines of code. I think that is a good guideline but it should not be considered a requirement. Another guideline is #23 about Stringbuilder. It is extremely easy to crticize use of the String class but developer efficiency needs to be balanced with machine efficiency. Sometimes the gain in machine efficiency does not justify the reduction of programmer productivity. Programmers should be proficient with the use of Stringbuilder but reviewers need to be able to overlook use of the String class when the affect on performance is insignificant.
Sam HobbsPosted Jun 12, 2013, 1:21 PM
I think these guidelines should be separated into categories. One category should be for performance. Another category should be for conventions that are a matter of preference. Another category should be for conventions that significantly affect programmer productivity.
Mohammed HameedPosted Jun 12, 2013, 7:13 AM
thanks Dinesh. I got very good response in codeproject, expecting same response here as well :)
Dinesh BeniwalPosted Jun 12, 2013, 7:01 AM
Good Work, Welcome to the C# Corner Mohammed
Mohammed HameedPosted Jun 12, 2013, 5:49 AM
thanks
Keyur PatelPosted Jun 12, 2013, 4:47 AM
It is really good article on Coding Guidelines.