← ClaudeAtlas

modern-csharplisted

C# 12–14 language features with practical patterns — primary constructors, collection expressions, records, pattern matching, nullable reference types, and more.
zdanovichnick/dotnet-pilot · ★ 3 · AI & Automation · score 76
Install: claude install-skill zdanovichnick/dotnet-pilot
# Modern C# (12–14) Reference for language features available in .NET 8+. Used by `dnp-planner` and `dnp-tdd-developer-hard`. ## Primary Constructors (C# 12) Eliminates constructor boilerplate. Parameters are in scope for the entire class body. ```csharp // Before public class OrderService { private readonly IOrderRepository _repo; private readonly ILogger<OrderService> _logger; public OrderService(IOrderRepository repo, ILogger<OrderService> logger) { _repo = repo; _logger = logger; } } // After (C# 12) public class OrderService(IOrderRepository repo, ILogger<OrderService> logger) { public async Task<Order?> GetByIdAsync(int id, CancellationToken ct) { logger.LogInformation("Fetching order {Id}", id); return await repo.GetByIdAsync(id, ct); } } ``` **Caveat**: primary constructor parameters are captured by reference — if you need a private field (e.g., for mutation tracking), assign explicitly: `private readonly IOrderRepository _repo = repo;` ## Collection Expressions (C# 12) Unified syntax for arrays, lists, and spans. Supports spread (`..`) operator. ```csharp // Array int[] ids = [1, 2, 3]; // List<T> List<string> tags = ["dotnet", "csharp"]; // Spread — merge sequences var basePermissions = new[] { "read", "list" }; string[] adminPermissions = [..basePermissions, "write", "delete"]; // Empty collection IReadOnlyList<string> empty = []; // In method calls ProcessItems([1, 2, 3]); ``` ## Record