Skip to content

Latest commit

 

History

History
43 lines (28 loc) · 1.36 KB

CSharpStyles.md

File metadata and controls

43 lines (28 loc) · 1.36 KB

C# Coding Style - Microsoft Coding Styles and Rules

Naming Conventions

  • Use PascalCase for class names and method names.
  • Use camelCase for variable names and parameter names.
  • Use uppercase for constants.

Indentation and Formatting

  • 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.

Comments

  • Use XML comments for documenting classes, methods, and properties.
  • Use single-line comments (//) for short comments within code.

Language Features

  • 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.

Error Handling

  • Use try-catch blocks for handling exceptions.
  • Use specific exception types when possible.
  • Use finally blocks for cleanup code.

Code Organization

  • Use regions to group related code sections.
  • Use partial classes for splitting large classes into multiple files.

Miscellaneous

  • 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.