wshaddix/dotnet-skills/csharp-coding-standards
Claude Code and agent skill by wshaddix/dotnet-skills
- community
Checking that the SKILL.md file is still in the repository.
Write modern, high-performance C# code using records, pattern matching, value objects, async/await, Span<T>/Memory<T>, and best-practice API design patterns. Emphasizes functional-style programming with C# 12+ features. Use when writing new C# code or refactoring existing code, designing public APIs for libraries or services, optimizing performance-critical code paths, or building async/await-heavy applications.
Install
npx vskill@latest install wshaddix/dotnet-skills/csharp-coding-standardsSKILL.md
Modern C# Coding Standards
When to Use This Skill
Use this skill when:
- Writing new C# code or refactoring existing code
- Designing public APIs for libraries or services
- Optimizing performance-critical code paths
- Implementing domain models with strong typing
- Building async/await-heavy applications
- Working with binary data, buffers, or high-throughput scenarios
Core Principles
- Immutability by Default - Use
recordtypes andinit-only properties - Type Safety - Leverage nullable reference types and value objects
- Modern Pattern Matching - Use
switchexpressions and patterns extensively - Async Everywhere - Prefer async APIs with proper cancellation support
- Zero-Allocation Patterns - Use
Span<T>andMemory<T>for performance-critical code - API Design - Accept abstractions, return appropriately specific types
- Composition Over Inheritance - Avoid abstract base classes, prefer composition
- Value Objects as Structs - Use
readonly record structfor value objects
Naming Conventions
General Rules
| Element | Convention | Example | |
|---|---|---|---|
| Namespaces | PascalCase, dot-separated | MyCompany.MyProduct.Core | |
| Classes, Records, Structs | PascalCase | OrderService, OrderSummary | |
| Interfaces | I + PascalCase | IOrderRepository | |
| Methods | PascalCase | GetOrderAsync | |
| Properties | PascalCase | OrderDate | |
| Events | PascalCase | OrderCompleted | |
| Public constants | PascalCase | MaxRetryCount | |
| Private fields | _camelCase | _orderRepository | |
| Parameters, locals | camelCase | orderId, totalAmount | |
| Type parameters | T or T + PascalCase | T, TKey, TValue | |
| Enum members | PascalCase | OrderStatus.Pending |
Async Method Naming
Suffix async methods with Async:
Boolean Naming
Prefix booleans with is, has, can, should, or similar:
Collection Naming
Use plural nouns for collections:
File Organization
One Type Per File
Each top-level type (class, record, struct, interface, enum) should be in its own file, named exactly as the type. Nested types stay in the containing type's file.
File-Scoped Namespaces
Always use file-scoped namespaces (C# 10+):
Using Directives
Place using directives at the top of the file, outside the namespace. With <ImplicitUsings>enable</ImplicitUsings> (default in modern .NET), common namespaces are already imported.
Order of using directives:
System.*namespaces- Third-party namespaces
- Project namespaces
Code Style
Braces
Always use braces for control flow, even for single-line bodies:
Expression-Bodied Members
Use expression bodies for single-expression members:
var Usage
Use var when the type is obvious from the right-hand side:
Null Handling
Prefer pattern matching over null checks:
String Handling
Prefer string interpolation over concatenation or string.Format:
Access Modifiers
Always specify access modifiers explicitly. Do not rely on defaults:
Modifier Order
Type Design
Seal Classes by Default
Seal classes that are not designed for inheritance. This improves performance (devirtualization) and communicates intent:
Only leave classes unsealed when you explicitly design them as base classes.
Prefer Composition Over Inheritance
Interface Segregation
Keep interfaces focused. Prefer multiple small interfaces over one large one:
Language Patterns
See Language Patterns for detailed guidance on:
- Records for Immutable Data (C# 9+)
- Value Objects as readonly record struct
- Pattern Matching (C# 8-12)
- Nullable Reference Types (C# 8+)
- Composition Over Inheritance
Performance Patterns
See Performance Patterns for detailed guidance on:
- Async/Await Best Practices
- Span<T> and Memory<T> for Zero-Allocation Code
API Design Principles
See API Design Principles for detailed guidance on:
- Accept Abstractions, Return Appropriately Specific
- Method Signatures Best Practices
Error Handling
See Error Handling for detailed guidance on:
- Result Type Pattern (Railway-Oriented Programming)
Testing Patterns
CancellationToken Conventions
Accept CancellationToken as the last parameter in async methods. Use default as the default value for optional tokens:
Always forward the token to downstream async calls. Never ignore a received CancellationToken.
XML Documentation
Add XML docs to public API surfaces. Keep them concise:
Do not add XML docs to:
- Private or internal members (unless it's a library's
InternalsVisibleToAPI) - Self-evident members (e.g.,
public string Name { get; }) - Test methods
Avoid Reflection-Based Metaprogramming
See Anti-Patterns for detailed guidance on:
- Why to avoid AutoMapper, Mapster, and similar reflection-based libraries
- Using explicit mapping methods instead
- UnsafeAccessorAttribute for legitimate reflection needs
Anti-Patterns to Avoid
See Anti-Patterns for detailed guidance on:
- Mutable DTOs
- Classes for value objects
- Deep inheritance hierarchies
- Exposing mutable collections
- Forgetting CancellationToken
- Blocking on async code
Code Organization
Analyzer Enforcement
Configure these analyzers in Directory.Build.props or .editorconfig to enforce standards automatically:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/csharp-coding-standards/SKILL.md
Popularity
- Repository stars
- 25
- Repository forks
- 2
- 7-day trend score
- 16
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 14 May 2026, 5 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/wshaddix/dotnet-skills/csharp-coding-standards)