Home › .NET / ASP.NET Core › C# / .NET Copilot path instructions
C# / .NET Copilot path instructions
Path-specific Copilot instructions for C# files on .NET 10: nullable types, async, records, and logging.
GitHub Copilot.NET / ASP.NET Core
How to use
Save this as .github/instructions/csharp.instructions.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.
.github/instructions/csharp.instructions.mdDownload ---
applyTo: "**/*.cs"
description: C# conventions
---
# C# (.NET 10)
- Nullable reference types are enabled. Model optionality with `?` and handle it; don't use `!` to silence warnings.
- File-scoped namespaces, primary constructors for DI-only classes, `record` for immutable data, collection expressions (`[]`).
- Async I/O everywhere: `async Task`/`ValueTask`, accept and pass `CancellationToken`, never `.Result`/`.Wait()`/`async void` (except event handlers).
- Use `ILogger<T>` with message templates (`"Processing {OrderId}"`), not interpolated strings.
- Guard clauses with `ArgumentNullException.ThrowIfNull(x)` / `ArgumentException.ThrowIfNullOrEmpty(s)`.
- Prefer pattern matching (`is`, `switch` expressions) over casts and long if/else chains.
- LINQ for clarity, loops for hot paths; materialize EF queries once (`ToListAsync`).
- `IDisposable`/`IAsyncDisposable` resources in `using`/`await using`.
- Configuration via the options pattern with validation (`ValidateOnStart`).
- Public APIs get XML doc comments.
## Check
`dotnet build -warnaserror && dotnet test && dotnet format --verify-no-changes`.