modern-csharp-coding-standards

Guide modern C# 12+ development with records, pattern matching, and Span<T>.

Updated Dec 4, 2022
One-click install
npx skills add https://github.com/devingoble/CloudOStat --skill modern-csharp-coding-standards-devingoble
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: modern-csharp-coding-standards
Source: https://github.com/devingoble/CloudOStat/tree/main/.github/skills/csharp-coding-standards
Command: npx skills add https://github.com/devingoble/CloudOStat --skill modern-csharp-coding-standards-devingoble

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance and best practices for writing modern, high-performance C# code, ensuring maintainability, type safety, and efficiency.

Core Features & Use Cases

  • Modern C# Features: Leverages records, pattern matching, async/await, Span<T>/Memory<T>, and C# 12+ features.
  • API Design: Emphasizes best practices for designing robust and performant APIs.
  • Performance Optimization: Focuses on zero-allocation patterns and efficient code.
  • Use Case: Refactor an existing C# application to adopt immutable records, improve async operations, and utilize Span<T> for critical performance paths, leading to a more maintainable and faster codebase.

Quick Start

Apply modern C# coding standards to the provided C# code snippet.

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 use Span<T> and Memory<T> in C# to optimize performance?

To write high-performance C# code, use Span<T> and Memory<T> to process memory regions directly without allocating new arrays. This zero-allocation technique ensures optimal efficiency and minimizes garbage collection overhead in critical performance paths.

What are the best practices for modern C# async/await API design?

Best practices for modern C# async/await API design involve leveraging best-practice patterns for robust operations, ensuring type safety, and improving asynchronous efficiency to build maintainable and high-performance APIs.

Should I use C# records for immutable data instead of classes?

Use C# records for immutable data to enforce type safety and functional-style programming. Records provide built-in value equality and immutability, making your codebase more maintainable and reducing side effects compared to traditional mutable classes.

How do I refactor existing C# code to use pattern matching effectively?

Refactor existing C# code to use pattern matching by replacing complex if-else chains with type-based and property patterns. This modern C# feature improves code readability and maintainability while ensuring robust type checking.

Does adopting C# 12 coding standards require significant changes to my current codebase?

Adopting C# 12 coding standards does not require a full rewrite; you can incrementally refactor critical performance paths to use records, pattern matching, and Span<T>. This approach improves efficiency and maintainability without disrupting existing application logic.

When should I avoid zero-allocation techniques in C# performance optimization?

Avoid zero-allocation techniques like Span<T> when dealing with long-term data storage or when complexity obscures code maintainability. Reserve these high-performance C# patterns for critical execution paths where minimizing garbage collection overhead justifies the added structural complexity.