Skip to content

Commit 39b4f98

Browse files
Update instructions/csharp-best-practices.instructions.md
Co-authored-by: Copilot <[email protected]>
1 parent a9a0688 commit 39b4f98

File tree

1 file changed

+1
-47
lines changed

1 file changed

+1
-47
lines changed

instructions/csharp-best-practices.instructions.md

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,4 @@
1-
---
2-
applyTo: '**/*.cs'
3-
description: 'C# best practices and formatting guidelines for AI code generation (all versions).'
4-
---
5-
6-
# C# Best Practices for AI Code Generation Instructions
7-
8-
## Code Style and Formatting
9-
10-
### Namespace Declarations
11-
12-
- Use file-scoped namespace declarations when using C# 10+ (`namespace MyNamespace;`)
13-
- For older versions, use traditional block-scoped namespaces with proper indentation
14-
- Keep namespace declarations consistent within the project
15-
16-
### Access Modifiers
17-
18-
- Explicitly declare access modifiers for all members
19-
- Use `readonly` for fields that are only assigned in constructors
20-
- Use `const` for compile-time constants
21-
- Follow principle of least privilege for access levels
22-
23-
### Type Declarations
24-
25-
- Use `var` for local variables when the type is obvious from the right side
26-
- Use explicit types for method parameters, return types, and field declarations
27-
- Prefer target-typed expressions when the type is clear from context
28-
- Use meaningful and descriptive type names
29-
30-
### Method and Property Formatting
31-
32-
- Use expression-bodied members for simple one-line implementations
33-
- Place opening braces on new lines for methods, classes, and namespaces
34-
- Use auto-implemented properties when appropriate
35-
- Implement properties with backing fields only when additional logic is needed
36-
37-
## Modern C# Patterns
38-
39-
### Null Safety
40-
41-
- Use null-conditional operators (`?.`, `??`, `??=`) when available
42-
- Validate parameters with appropriate null checks
43-
- Use `string.IsNullOrEmpty()` and `string.IsNullOrWhiteSpace()` for string validation
44-
- Consider nullable reference types when using C# 8+
45-
46-
### String Handling
47-
1+
# (File removed)
482
- Use string interpolation `$""` instead of `String.Format()` or concatenation
493
- Use `StringBuilder` for extensive string manipulation
504
- Prefer `string.Equals()` with `StringComparison` for culture-aware comparisons

0 commit comments

Comments
 (0)