CS

C# Defaults

Core C# coding conventions

Details

Language / Topic
csharpC#
Category
Style Guide

Rules

balanced
- Follow .NET naming: `PascalCase` for public members and types, `camelCase` for parameters and locals, `_camelCase` for private fields.
- Use C# 12+ features: primary constructors, collection expressions, pattern matching.
- Use `var` for local variables when the type is obvious from the right side — use explicit types when it improves readability.
- Use file-scoped namespaces (`namespace MyApp;`) to reduce nesting — available in C# 10+.
- Use `record` types for immutable data. Use `readonly` on structs and fields that shouldn't change.
- Prefer `async`/`await` for all I/O operations — never block with `.Result` or `.Wait()`.
- Use nullable reference types (`#nullable enable`). Annotate nullability explicitly.
- Use pattern matching (`is`, `switch` expressions) over type casting and `if`/`else` chains.
- Prefer LINQ methods (`.Where()`, `.Select()`, `.Any()`) over manual loops for querying collections.