How to Review C# Code: A Practical Guide for Developers

Reviewing C# code well means checking more than syntax. This guide covers what to look for in .NET pull requests and how automated tools like CodeInspector complement manual review.

Video explainer (1:13) · Watch with transcript

Start with context

Before reading individual lines, understand the change: which service or layer is affected, whether the PR touches public APIs, and what failure modes matter for this module.

Skim the diff for scope — a small PR in a critical payment path deserves different scrutiny than a documentation-only change.

Exception handling and reliability

C# code should fail predictably. Watch for empty catch blocks, overly broad catch (Exception) handlers that swallow root causes, and missing logging when exceptions are handled locally.

Async code adds complexity: verify await is used correctly, avoid blocking on .Result or .Wait(), and ensure cancellation tokens propagate where long-running work exists.

  • Are exceptions logged with enough context to debug production incidents?
  • Does the code rethrow or wrap exceptions without losing stack traces?
  • Are IDisposable and IAsyncDisposable resources released reliably?

Structure and complexity

Long methods and high cyclomatic complexity make C# code expensive to change. If a method mixes validation, mapping, persistence, and notification, suggest extracting focused helpers or services.

Large classes with many responsibilities often indicate missing domain boundaries — note them even when the PR compiles and tests pass.

Security and configuration

Scan for hardcoded secrets, connection strings, and API keys. Prefer configuration providers and secret stores. Validate that user input is handled safely before it reaches queries or file operations.

Authentication and authorization checks belong as close to entry points as practical — do not rely on callers to enforce access control.

When to run automated analysis

Manual review cannot re-read every file on every PR. Run a C# code analyzer like CodeInspector on the repository periodically or before releases to catch pattern-based issues — empty catches, complexity hotspots, and security signals — across the full codebase.

Use automated findings to prioritize human review time on architecture and business logic.

Related