modern-csharp-coding-standards

Write modern C# code using records, pattern matching, Span<T>, and async best practices.

3|Updated Aug 8, 2026
One-click install
npx skills add https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer --skill modern-csharp-coding-standards-jose-polanco-oxte
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: modern-csharp-coding-standards
Source: https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer/tree/main/.agents/skills/csharp/sub-skills/modern-csharp-coding-standards
Command: npx skills add https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer --skill modern-csharp-coding-standards-jose-polanco-oxte

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Inconsistent or outdated C# code leads to bugs, poor performance, and hard-to-maintain codebases. This Skill provides a comprehensive set of modern C# coding standards covering C# 12+ features so you write idiomatic, performant, and type-safe code from the start. ## Core Features & Use Cases - Immutable Data Modeling: Use record types and readonly record structs for DTOs, value objects, and domain entities with built-in validation. - Performance Patterns: Apply Span<T>, Memory<T>, ArrayPool, and ValueTask for zero-allocation, high-throughput code paths. - Robust API Design: Accept abstractions, return appropriately specific types, propagate CancellationToken, and use Result<T, TError> for expected errors instead of exceptions. - Use Case: When refactoring a legacy service, apply these standards to replace inheritance hierarchies with composition, convert mutable classes to records, and rewrite string parsing with Span<T> to eliminate allocations. ## Quick Start Ask the AI to write or refactor a C# class following modern C# coding standards with records, pattern matching, and nullable reference types.

Frequently Asked Questions about modern-csharp-coding-standards

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write modern C# code with records and pattern matching?

Use record types for immutable DTOs and domain entities, and readonly record structs for value objects. Combine them with switch expressions, property patterns, and relational patterns to replace verbose if-else chains with expressive matching logic.

When should I use record struct vs record class in C#?

Use record class for entities, aggregates, and DTOs with multiple properties where reference semantics fit. Use readonly record struct for value objects like Money or OrderId, since they get value semantics, stack allocation, and no GC pressure.

How do I avoid allocations in performance-critical C# code?

Use Span<T> and ReadOnlySpan<T> for synchronous slicing and parsing without allocations, Memory<T> when crossing await boundaries, and ArrayPool<T> for large temporary buffers. Replace substring calls with span slicing to eliminate intermediate string allocations.

Should I use exceptions or Result types for error handling in C#?

Use a Result<T, TError> type for expected errors like validation failures, business rule violations, and not-found cases. Reserve exceptions for unexpected failures such as network errors, system faults, or programming bugs.

Does modern C# still need async and CancellationToken everywhere?

Yes, I/O-bound operations should be async end-to-end with CancellationToken parameters defaulted and propagated through the call stack. Never block on async code with .Result, and use ValueTask for frequently-called methods that often complete synchronously.

When is inheritance acceptable in modern C# design?

Inheritance is acceptable mainly for framework requirements like ControllerBase in ASP.NET Core or custom exceptions. Application code should prefer composition with interfaces, static helper classes, and records modeling variants instead of abstract base class hierarchies.