C# coding conventions for clearer, safer .NET code

These are my top 10 C# coding conventions: a compact set of rules I use to keep C# readable, reviewable and consistent across projects. They cover naming, method design, nullability, asynchronous code and the automation that turns personal habits into team standards. The goal is code that explains itself without relying on tribal knowledge or the memory of whoever wrote it last.

I treat conventions as defaults rather than a replacement for judgement. A team can make an informed exception when a boundary calls for one, but that decision should be visible and rare. This matters in Australian software teams, where a .NET service in Sydney may be maintained by colleagues in Melbourne, Brisbane or Perth. Shared spelling, casing and formatting reduce the tiny negotiations that otherwise consume review time.

The conventions also reflect how modern C# is built. Nullable reference types, async and await, immutable records, and first-class DateOnly and DateTimeOffset values are now normal parts of a healthy .NET codebase. Roslyn analyzers can catch many mistakes before review, so style belongs in source control and CI rather than in a collection of well-meaning comments. Consistency lets the compiler and tooling carry more of the load.

I have kept these habits while working across full-stack products and line-of-business systems, and I adjust the details to suit the project. The language and framework remain the same even when teams, domains and delivery schedules differ. What follows is the version I would put into a new C# repository today, whether the product serves Australian customers or an international market.

Use names that reveal intent

Start with the casing established by the .NET naming guidelines. Types, methods, properties, events and enum members use PascalCase, while parameters and local variables use camelCase. Interface names receive the familiar I prefix, such as IInvoiceRepository. Following these conventions removes low-value decisions from reviews and makes unfamiliar code easier to navigate.

Private fields use an underscore prefix followed by camelCase, including _auditClock. Static readonly fields normally use PascalCase, and constants follow the same pattern. Prefer readonly when a reference should not be replaced after construction. These details are easy to automate, but establishing them early prevents inconsistent variations from spreading through a solution.

Names should describe the domain rather than the implementation. InvoiceDueDate communicates more than Date1, while customerRepository says what an object represents and why it exists. Reserve abbreviations such as Id, Url and Http for terms that are already established. Australian spelling may use “organise”, but identifiers should generally follow the framework’s American English API names, such as Initialize and Serialize.

Keep methods small and responsibilities clear

A method should have one reason to change. That does not mean splitting every method into artificial three-line pieces; it means avoiding methods that validate input, calculate a result, write to a database and send a notification under one vague name. Extract cohesive steps when the extra abstraction makes the workflow easier to understand. This is particularly valuable in business systems where tax, billing and reporting rules evolve independently.

Guard clauses should handle invalid conditions close to the start of a method. Throw ArgumentNullException for a missing required object and ArgumentException when a supplied value falls outside its permitted range. Guard clauses keep the successful path at the lowest indentation level and separate precondition failures from normal business outcomes. Exceptions remain appropriate for exceptional conditions, rather than being used to implement ordinary branching.

Expression-bodied members are useful for simple properties and short, obvious transformations. They become noisy when they conceal control flow, repeated work or domain logic. I prefer a conventional block when the body needs explanation, especially for calculations, asynchronous calls and validation. Clever code can be intellectually satisfying, but maintainable code should let a reviewer follow the business rule without reconstructing several implicit operations.

Make nullability, money, and dates explicit

Nullable reference types should be enabled in every modern C# project. The annotations do not prove that a value is safe, but they expose assumptions that might otherwise remain hidden. Avoid using the null-forgiving operator simply to silence a warning. Fix the underlying flow with a guard, an early return, a nullable return type or a clearer state model. Occasional suppression is justified at a verified interop boundary, provided the reason is documented.

Money requires special care. Australian billing systems frequently calculate GST and reconcile amounts to the nearest cent, so use decimal for currency values and tax rates. Floating-point values such as double are unsuitable when calculations must remain exact. Keeping the currency explicit in names such as audTotal also prevents accidental assumptions when a product serves customers in different markets.

Dates and times deserve equally precise types. Use DateOnly for calendar dates without a time or time zone, and DateTimeOffset when an instant must be retained. Australian teams often discuss dates in day-first form, such as 04/07/2026, but that notation is ambiguous internationally and can be misread even within Australia. Accept structured input, parse using an invariant culture with explicit formats, and use ISO 8601 for interchange and persisted timestamps.

Ten conventions I apply in every C# project

The first group defines the vocabulary and structure of a C# codebase:

The second group establishes predictable behaviour at boundaries and within implementations:

Taken together, these rules provide a baseline for both application code and tests. A test method should use the same naming and construction patterns as the production code it exercises. Consistent conventions make failures easier to locate because the reader does not also need to decode inconsistent casing or dependency patterns. The standard should apply everywhere code receives professional review.

Make the conventions enforceable

Put the agreed rules in a repository-level .editorconfig file and enable the relevant .NET analyzers. dotnet format can apply the formatting rules, while --verify-no-changes can fail a build when a contributor has missed one. Treat analyzer warnings as errors selectively, beginning with dependable correctness rules rather than enabling every possible style opinion. A strict setting that developers constantly bypass provides less value than a focused set they can trust.

The same checks should run in CI for every pull request. A small build script or GitHub Actions workflow can restore packages, build the solution, run tests and verify formatting without requiring manual steps. For distributed Australian teams, keep scheduled jobs and machine-readable logs in UTC while presenting local times only in human-facing reports. This prevents daylight-saving changes around Sydney and Melbourne from shifting jobs at an unexpected hour, and it keeps systems aligned with teams in Brisbane and Perth.


Copy the rules your team has agreed into .editorconfig today, enable the corresponding analyzers, and make the next pull request demonstrate them. Record deliberate exceptions beside the affected code so the reason survives staff changes and future maintenance.

Make the automated checks the path of least resistance, then revisit the conventions when the language, framework or product domain changes. A personal checklist becomes valuable only when it is shared, enforced and easy to apply under delivery pressure.