C# Code: Best Practices for Clean and Maintainable Software (video)
C# best practices: naming, SOLID, exceptions, nullability, async, DI, LINQ, testing, and static analysis for modern .NET.
Transcript
C# Code: Best Practices for Clean and Maintainable Software. Here's the short version.
Clean C# code is readable, testable, and aligned with modern .NET conventions. Advice differs slightly between legacy .NET Framework and .NET 8+ — this guide focuses on current .NET with nullable reference types and async-first I/O.
Naming and structure. Types and methods — PascalCase; locals — camelCase. Async methods suffix Async; avoid async void except handlers. Keep classes focused; prefer composition over giant god services.
Here's the problem in code: empty catch.
And here's the fix: log and handle deliberately.
Nullability, async, and DI. Enable nullable reference types; guard or throw on null. Use await instead of .Result on async paths. Inject dependencies via constructor; program to interfaces. Keep LINQ readable — extract complex queries to named methods.
Testing and analysis. Unit test behavior via public APIs.
Want to find these issues in your own code? Connect your GitHub repository to CodeInspector. You'll get findings with the file, line, severity, and a recommended fix, plus HTML and PDF reports for your team. Start free at codeinspector.app.
More videos
- CodeInspector product demo (0:54)
- CodeInspector Now Works Inside Claude: Scan and Fix Code in One Conversation (video) (1:20)
- throw vs throw ex in C#: Why throw ex Destroys Your Stack Trace (video) (1:22)
- Thread.Sleep vs Task.Delay in C#: Which to Use and Why (video) (1:38)
- Task.Result and .Wait() Deadlocks in C#: Why Sync-over-Async Hangs (video) (1:47)
- ILogger Best Practices in .NET: Structured Logging That Helps You Debug (video) (1:20)