C# Best Practices and Code Review Checklist

Mohammad Shoeb
.Net Programming
Published in
5 min readAug 11, 2020

--

In this blog, I am going to share some of the best practices for C# code review. Some of the code review guidelines are independent of any programming language and can be applied in any programming language as a best practice for writing code.

1. Make sure that there shouldn’t be any project warnings, treat warning as errors

2. It will be much better if Code Analysis is performed on a project (with all Microsoft Rules enabled) and then remove the warnings.

3. Use asynchronous programming using C# async await where application, as it tremendously improves the performance

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/

4. Use C# new language features, for example use nameof operator to get the property/method names instead of hard coding it

if (IsNullOrWhiteSpace(lastName))

throw new ArgumentException(message: “Cannot be blank”, paramName: nameof(lastName));

5. All unused usings need to be removed. Code cleanup for unnecessary code is always a good practice.

6. ‘null’ check needs to be performed wherever applicable to avoid the Null Reference Exception at runtime, use C# 6.0 new feature “Null-conditional operators” for this, one example as given below

var first = person?.FirstName;

--

--

Mohammad Shoeb
.Net Programming

Solution Architect (.NetFull stack, Multi cloud Architect) - Certified AWS, Azure, GCP Professional Architect