- Use PascalCase for class names and method names.
- Use camelCase for variable names and parameter names.
- Use uppercase for constants.
- Use spaces for indentation, with 4 spaces per level.
- Use braces on a new line for control structures (if, for, while, etc.).
- Use a single space between keywords and parentheses.
- Use XML comments for documenting classes, methods, and properties.
- Use single-line comments (//) for short comments within code.
- Use var keyword for local variables when the type is obvious.
- Use explicit types for method parameters and return types.
- Use async/await for asynchronous programming.
- Use try-catch blocks for handling exceptions.
- Use specific exception types when possible.
- Use finally blocks for cleanup code.
- Use regions to group related code sections.
- Use partial classes for splitting large classes into multiple files.
- Avoid using abbreviations in names.
- Avoid using magic numbers; use named constants instead.
- Avoid using unnecessary parentheses.
For more details, refer to the Microsoft C# Coding Conventions.