dotnet-modern-csharp

Modernizes C# code using version-aware language features matched to the repo's target framework and LangVersion.

Updated Mar 31, 2026
One-click install
npx skills add https://github.com/zhenpengLai/myuseskill --skill dotnet-modern-csharp-zhenpenglai
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dotnet-modern-csharp
Source: https://github.com/zhenpengLai/myuseskill/tree/main/dotnet-modern-csharp
Command: npx skills add https://github.com/zhenpengLai/myuseskill --skill dotnet-modern-csharp-zhenpenglai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Teams working in .NET repositories often struggle to know which modern C# language features are safe to adopt given their target framework and LangVersion settings, risking unsupported syntax, accidental preview usage, or unnecessary mass rewrites. ## Core Features & Use Cases - Version-Aware Feature Selection: Detects the real language ceiling from the repo's TFM and explicit LangVersion, mapping .NET 9 to C# 13 and .NET 10 to C# 14. - Migration Guidance: Provides before/after patterns for migrating to C# 8 through C# 14, including primary constructors, collection expressions, records, raw string literals, and the field keyword. - Safe Modernization Workflow: Uses a plan-execute-review loop with bootstrap steps for SDK or toolchain upgrades and explicit validation against build, analyzer, and style rules. - Use Case: When upgrading a service to .NET 9, ask which C# 13 features are safe to adopt and receive concrete refactors such as System.Threading.Lock and params collections that compile against the repo's actual settings. ## Quick Start Ask the assistant to review your C# repository and modernize the code using only language features supported by its target framework and LangVersion.

Frequently Asked Questions about dotnet-modern-csharp

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

FAQPage Schema
How do I know which C# features I can use on .NET 9?▼

.NET 9 maps to C# 13, so features like params collections, System.Threading.Lock, and partial properties are supported. Check your csproj for TargetFramework and any explicit LangVersion, since an explicit setting overrides the default mapping.

How to migrate C# code to primary constructors and collection expressions?▼

Primary constructors and collection expressions require C# 12 on .NET 8 or later. Replace traditional constructor boilerplate by declaring parameters on the type declaration, and replace new[] or new List initializers with bracket syntax like [1, 2, 3].

Should I set LangVersion to latest in my .NET project?▼

No, setting LangVersion to latest makes builds machine-dependent because the result varies with the installed SDK. Prefer letting the target framework determine the language version, or pin an explicit version in project or shared MSBuild config.

Can I use C# preview features in a production repository?▼

Preview features should be opt-in only and never assumed just because the local machine has a newer SDK. For example, the field keyword was preview in C# 13-era tooling but became stable in C# 14 on .NET 10.

When should I avoid modernizing C# syntax?▼

Avoid mass-rewriting a working codebase just to use newer syntax, and skip this approach for non-C# languages like F# or VB. Modernize opportunistically when already touching code, prioritizing correctness and readability over cosmetic changes.