Why C# Developers Choose Claude Code
Full .NET stack awareness
Understands ASP.NET Core, EF Core, Blazor, MAUI, Orleans, Aspire — and which version you're on.
Nullable & type safe
Generates null-safe code by default. Enables nullable reference types, uses records, avoids NRE landmines.
Modern C# idioms
Uses records, primary constructors, required members, collection expressions, and switch expressions correctly.
xUnit / NUnit / Moq
Generates complete test suites with mocks, FluentAssertions, and theory-based parameterised tests.
Project Setup for Maximum Productivity
CLAUDE.md for .NET Projects
NuGet & Dependency Management
ASP.NET Core Web API
Controllers & Endpoints
Background Services & Queuing
Entity Framework Core
Modern C# Language Features
Records & Immutable Types
Pattern Matching & Switch Expressions
Async/Await & Concurrency
Dependency Injection & Configuration
Blazor (WebAssembly & Server)
Testing C# with xUnit, NUnit & Mocking
LINQ & Functional Patterns
Tooling, Docker & CI/CD
All 40+ Prompts at a Glance
How to use these prompts
Paste any prompt directly into Claude Code (CLI: claude). Prefix with your context — e.g. "Given my ProductsController at src/Api/Controllers/ProductsController.cs, …" — for best results. Claude Code reads the file automatically if you mention the path.
| Category | Prompt summary |
|---|---|
| .NET Setup | CLAUDE.md for Clean Architecture .NET 9 |
| .NET Setup | Scaffold 3-project solution with DI + Serilog |
| .NET Setup | global.json + .editorconfig + Directory.Build.props |
| NuGet | Audit outdated + vulnerable packages |
| NuGet | Central Package Management migration |
| ASP.NET Core | CRUD controller with ProblemDetails |
| ASP.NET Core | Migrate controllers to Minimal APIs |
| ASP.NET Core | FluentValidation + 400 ProblemDetails |
| ASP.NET Core | JWT auth + refresh token controller |
| ASP.NET Core | Global exception handling middleware |
| ASP.NET Core | Scalar/Swagger OpenAPI with XML docs |
| ASP.NET Core | Channel<T> background worker with concurrency |
| ASP.NET Core | Polly v8 resilience pipeline for HttpClient |
| EF Core | Paginated query with projection (no N+1) |
| EF Core | Safe schema migration with backfill |
| EF Core | Bulk update/delete with ExecuteUpdateAsync |
| EF Core | Owned Entity value objects (Address) |
| EF Core | Generic repository + specification pattern |
| EF Core | AsNoTracking audit + compiled queries |
| Records | DTO refactor to positional records |
| Records | Result<T,E> discriminated union railway |
| Pattern matching | Switch expression for notification dispatch |
| Pattern matching | State machine with exhaustive switch |
| Async | Sequential → parallel Task.WhenAll with error handling |
| Async | IAsyncEnumerable + Channel producer/consumer |
| Async | Distributed lock for singleton batch job |
| DI | IOptions/IOptionsSnapshot/IOptionsMonitor pattern |
| DI | Convention-based service scanning with Scrutor |
| Blazor | Generic DataTable component with sort/filter/page |
| Blazor | Cascading auth state + role-based rendering |
| Blazor | Clipboard API JavaScript interop wrapper |
| Blazor | Optimistic UI updates with rollback |
| xUnit | NSubstitute mocks + FluentAssertions full suite |
| xUnit | Theory tests with MemberData + JSON fixture file |
| Integration | WebApplicationFactory + Testcontainers PostgreSQL |
| Mutation | Stryker.NET mutation testing setup |
| Benchmark | BenchmarkDotNet for hot paths |
| LINQ | Nested foreach → LINQ method chain |
| LINQ | Chunk/DistinctBy/MinBy/MaxBy operators |
| Functional | Pipe composition with Result monad |
| Docker | Multi-stage Dockerfile with non-root user |
| CI/CD | GitHub Actions: build, test coverage, Docker push |
| Roslyn | Analyzer + code fix for Async suffix |
| MAUI | CommunityToolkit.Mvvm + platform permissions |
Frequently Asked Questions
<Nullable>enable</Nullable> in .csproj). It correctly distinguishes between string (non-nullable) and string? (nullable), uses the null-forgiving operator ! only when justified, and avoids null reference exceptions by using null-conditional operators (?.), null-coalescing (?? and ??=), and pattern matching (if (x is not null)). When auditing existing code, Claude identifies nullable annotation mismatches and adds the correct [NotNull], [MaybeNull] attributes. Prompt: "Enable nullable reference types across this project and fix all warnings — explain every case where you use ! and why it is safe."[ApiController], [Route], [HttpGet/Post/Put/Delete] attributes, produces OpenAPI-compatible responses, and wires up services in Program.cs. It understands the difference between scoped, transient, and singleton lifetimes and chooses the right one. Prompt: "Add a POST /api/orders endpoint with FluentValidation, a service interface injected via constructor, and a 201 Created response with the Location header set to the new resource URL."Include/ThenInclude for eager loading, AsNoTracking for read-only queries, and ExecuteUpdateAsync/ExecuteDeleteAsync for bulk operations in EF Core 7+. For migrations, it generates Up/Down methods correctly and flags destructive schema changes. Prompt: "Add a query that fetches orders with their line items and product names, filters by customer and date range, paginates using Skip/Take, and returns a lightweight DTO — avoiding the N+1 problem."required properties (C# 11), primary constructors (C# 12), collection expressions (C# 12), and ref readonly parameters appropriately. Prompt: "Refactor these DTOs to use records, add a domain model that uses a discriminated union-style hierarchy with pattern matching for processing, and keep the JSON serialization working."[Parameter], [CascadingParameter], [Inject] attributes, writes EventCallback<T> for child-to-parent communication, uses IJSRuntime for JavaScript interop, and scopes state management with services. It avoids common mistakes like calling StateHasChanged without await and mutating parameters from child components. Prompt: "Build a Blazor component that fetches paginated data from an API, shows a loading skeleton, handles errors with a retry button, and deep-links the current page via the URL."[Fact] and [Theory] + [InlineData]/[MemberData], NUnit tests with [Test] and [TestCase], and MSTest when required. For mocking, it writes Moq setups with Setup/Returns/Verify and NSubstitute equivalents. It correctly uses AutoFixture for test data, FluentAssertions for readable assertions, and arranges async tests with async Task and await. Prompt: "Write xUnit tests for this service class using NSubstitute for its two dependencies, cover the happy path, null input, and the case where the repository throws — use FluentAssertions."SelectMany for flattening, GroupBy for aggregations, Zip for pairing sequences, Chunk for batching (.NET 6+), and DistinctBy/MinBy/MaxBy (.NET 6+). It avoids ToList() materialisation mid-query unless necessary, uses lazy evaluation correctly, and knows when PLINQ (AsParallel()) is appropriate. Prompt: "Rewrite this nested foreach that builds a grouped report into LINQ — preserve the null-safety, avoid multiple enumeration, and add a benchmark comment showing the O(n) improvement."Related Resources
- 62 copy-paste Claude Code prompts — prompts by category
- Claude Code cheatsheet — CLI flags, shortcuts, slash commands
- Claude Code best practices — CLAUDE.md, permissions, TDD
- Claude Code sub-agents — parallel agent orchestration
- Claude Code for Java developers — Spring Boot, Gradle, JUnit 5
- Claude Code for Python developers — FastAPI, pytest, Django
- Claude Code for Go developers — Gin, gRPC, goroutines