Early previewThis guide is in development. Items tagged verify are still being checked against official docs.
nebx Learn
GitHub
Menu
Home/C#/Best practices
C#

C#

A productive, strongly typed language for the whole .NET platform.

Paradigm
OOP, functional features
Typing
Static, strong, nullable-aware
Memory
Generational GC
Runs
.NET runtime (JIT) or Native AOT
Concurrency
Tasks, async/await, channels

Best practices

Habits experienced C# teams agree on.

Enable nullable reference types

enable makes the compiler warn about possible null dereferences.

Use built-in dependency injection

Microsoft.Extensions.DependencyInjection: register services by lifetime (singleton, scoped, transient) and inject interfaces.

Async all the way

Once a call is async, keep callers async; pass CancellationToken through.

Dispose what you own

Wrap IDisposable / IAsyncDisposable in using or await using declarations.

Treat analyzer warnings as errors

Roslyn analyzers and .editorconfig keep a team's style consistent.

Saved in this browser only. Part of Clean code foundations (0/5).