C# Project
Language: C# October 1, 2025
Instruction file for C# projects with .NET and modern features.
---
applyTo: "**/*.cs"
---
# C# Development Instructions (2025)
_Last updated: October 2025_
- Always use the fetch tool to look up the latest C# documentation: https://docs.microsoft.com/dotnet/csharp
- Use .NET 8 or later for new projects
- Leverage modern C# features: records, pattern matching, nullable reference types
- Follow C# naming conventions: PascalCase for public members, camelCase for private fields
- Use async/await for asynchronous operations
- Implement dependency injection and SOLID principles
**Core Principles:**
- Use records for immutable data types
- Enable nullable reference types to prevent null reference exceptions
- Use pattern matching for type checking and deconstruction
- Implement proper exception handling with try-catch-finally
- Use LINQ for collection operations
- Follow Microsoft's coding conventions and style guide
**ASP.NET Core:**
- Use minimal APIs or controllers for building web APIs
- Implement dependency injection through constructor injection
- Use Entity Framework Core for database access
- Implement proper middleware pipeline
- Use configuration providers (appsettings.json, environment variables)
**Modern Features:**
- Use record types for DTOs and value objects
- Implement init-only properties for immutability
- Use top-level statements for cleaner program files
- Leverage pattern matching with switch expressions
- Use nullable reference types (enable in .csproj)
**Async Programming:**
- Use async/await for I/O-bound operations
- Avoid async void except for event handlers
- Use Task.WhenAll for parallel operations
- Implement proper cancellation with CancellationToken
**Testing:**
- Use xUnit, NUnit, or MSTest for unit testing
- Implement test-driven development when appropriate
- Use Moq or NSubstitute for mocking
- Write integration tests for APIs
**Performance:**
- Use Span<T> and Memory<T> for high-performance scenarios
- Implement object pooling for frequently allocated objects
- Use ValueTask for hot paths
- Profile with BenchmarkDotNet
**Summary:**
> For all C# work, always use the fetch tool to look up the latest documentation from https://docs.microsoft.com/dotnet/csharp. Write modern, type-safe .NET applications. C# .NET Backend Programming Language