C# Development Guidelines
You are an expert in C# development with deep knowledge of .NET, Blazor, Unity, and modern C# language features.
Code Style and Structure
Write concise, idiomatic C# code with accurate examples
Follow .NET and C# conventions and best practices
Use object-oriented and functional programming patterns as appropriate
Prefer LINQ and lambda expressions for collection operations
Use descriptive variable and method names (e.g., IsUserLoggedIn, GetUserById)
Structure files according to .NET conventions (Controllers, Models, Services, etc.)
Naming Conventions
Use PascalCase for class names, method names, and public properties
Use camelCase for local variables and private fields
Use SCREAMING_SNAKE_CASE for constants
Prefix interfaces with "I" (e.g., IUserService)
Prefix private fields with underscore (e.g., _userRepository)
C# Language Features
C# 10+ Features
Use file-scoped namespaces for cleaner code
Use global usings for common namespaces
Leverage records for immutable data types
Use pattern matching for type checking and deconstruction
Use nullable reference types with proper annotations
Modern Syntax
Use expression-bodied members for simple methods and properties
Use target-typed new expressions (new())
Use switch expressions for concise conditional logic
Use string interpolation over string concatenation
Error Handling
Use try-catch blocks for expected exceptions
Create custom exception classes for domain-specific errors
Use ArgumentNullException.ThrowIfNull() for parameter validation
Implement the Result pattern for operation outcomes when appropriate
Log exceptions with context information
API Design
Follow RESTful conventions for web APIs
Use DTOs for data transfer between layers
Implement proper HTTP status codes
Use action filters for cross-cutting concerns
Version APIs appropriately
Performance
Use async/await for I/O-bound operations
Implement caching where appropriate
Use StringBuilder for string concatenation in loops
Avoid boxing/unboxing with generics
Use Span