Code Review in C#: What to Check and How to Give Feedback to Beginners

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Code Review in C#: Where to Start and What to Look For



Code review is not just a formality, but a powerful tool for improving project quality and team growth. For beginner C# developers, the process of reviewing someone else's code often causes fear: "What if I miss a bug?", "How do I tell a colleague their code is bad?" In this article, we will break down what to pay attention to during code review in .NET projects and how to give feedback so that you are heard, not offended.



We won't talk about obvious things like syntax errors — the compiler catches those. Our goal is to learn to see issues with architecture, readability, and performance, as well as how to correctly formulate comments.



1. Architecture and SOLID Principles in C#



The first thing to check in C# code is whether it adheres to the SOLID principles. Even in a small method, you can see a violation of the Single Responsibility Principle.



What to check:

  • Method and class size. If a method is longer than 20-30 lines, it is likely doing too much. Suggest breaking it into several private methods.
  • Dependency Inversion. Classes should not create their dependencies using new. Instead, use Dependency Injection (DI). Example of bad code:


// Bad: the class creates the dependency itselfpublic class OrderService{    private readonly EmailSender _sender = new EmailSender();

public void ProcessOrder(Order order) { // logic... _sender.SendEmail(order.CustomerEmail); }}


The correct approach is through an interface and DI:



// Good: dependency is injectedpublic class OrderService{    private readonly IEmailSender _sender;

public OrderService(IEmailSender sender) { _sender = sender; }

public void ProcessOrder(Order order) { // logic... _sender.SendEmail(order.CustomerEmail); }}


  • Liskov Substitution Principle (LSP). Subtypes must not break the behavior of the base class. For example, if you have a Bird class with a Fly() method, and you create Penguin : Bird — this is an LSP violation, as penguins don't fly. It's better to define an IFlyable interface.


2. Error Handling and Exceptions in .NET



C# has a powerful exception system, but beginners often use it incorrectly. During code review, pay attention to the following points:



  • Empty catch blocks. Code like catch (Exception) { } is a ticking time bomb. The error is swallowed, and you will never know about the problem. Always log the exception or rethrow it.
  • Overly general exceptions. Catching Exception is bad practice. Try to catch specific types: SqlException, InvalidOperationException, etc.
  • Using exceptions for flow control. Do not use try-catch instead of if-else. Example of bad code:


// Bad: exception as part of logictry{    int.Parse(userInput);}catch (FormatException){    Console.WriteLine("Invalid format");}


The correct approach is int.TryParse():



// Good: check without exceptionif (int.TryParse(userInput, out int result)){    // work with result}else{    Console.WriteLine("Invalid format");}


3. Performance and Memory Management



For beginner C# developers, the topic of performance is often overlooked. However, code review is a great opportunity to point out inefficient constructs.



Typical issues:

  • Excessive

Blogs

Book Recommendations