DEV Community

Ahmed Shah
Ahmed Shah

Posted on • Updated on

๐Ÿ‘จโ€๐Ÿ’ป ๐——๐—ผ๐˜๐—ก๐—ฒ๐˜ ๐—–๐—ผ๐—ฑ๐—ถ๐—ป๐—ด ๐—–๐—ผ๐—ป๐˜ƒ๐—ฒ๐—ป๐˜๐—ถ๐—ผ๐—ป๐˜€ ๐—ณ๐—ผ๐—ฟ ๐—–๐—น๐—ฒ๐—ฎ๐—ป๐—ฒ๐—ฟ ๐—–๐—ผ๐—ฑ๐—ฒ!

๐Ÿ‘จโ€๐Ÿ’ป ๐——๐—ผ๐˜๐—ก๐—ฒ๐˜ ๐—–๐—ผ๐—ฑ๐—ถ๐—ป๐—ด ๐—–๐—ผ๐—ป๐˜ƒ๐—ฒ๐—ป๐˜๐—ถ๐—ผ๐—ป๐˜€ ๐—ณ๐—ผ๐—ฟ ๐—–๐—น๐—ฒ๐—ฎ๐—ป๐—ฒ๐—ฟ ๐—–๐—ผ๐—ฑ๐—ฒ!
I highly recommend following Microsoft's official C# coding conventions, which are designed to help us write clean, readable, and efficient code. ๐ŸŽฏ

1๏ธโƒฃ Naming: Microsoft suggests using PascalCase for class names, methods, and properties. For parameters and local variables, we should use camelCase. Choosing descriptive names is vital to enhance code comprehension.
2๏ธโƒฃ Brace Placement: Microsoft's convention uses the next-line style for braces. The opening brace is placed on a new line, aligned with the method or class declaration, while the closing brace is on a separate line, aligned with the beginning of the method or class.
3๏ธโƒฃ Indentation: Consistent indentation is crucial for code readability. Microsoft advises using four spaces for indentation, making the code structure clear and easy to follow.
4๏ธโƒฃ Comments and Documentation: Clear and concise comments are encouraged to explain complex logic or any potential gotchas. For public APIs, XML documentation should be provided to assist other developers using your code.
5๏ธโƒฃ Error Handling: Properly handle exceptions and avoid catching general exceptions unless necessary. Microsoft recommends catching specific exceptions and providing meaningful error messages.
6๏ธโƒฃ Code Organization: Follow the recommended project structure and namespace conventions to keep the codebase organized and maintainable as it grows.
7๏ธโƒฃ Avoid Magic Numbers: Assign meaningful constants or enumerations instead of using magic numbers, as it enhances code readability and maintainability.
8๏ธโƒฃ Null Checks: Validate inputs and handle null values appropriately to avoid unexpected runtime errors.
9๏ธโƒฃ LINQ Usage: Embrace Language-Integrated Query (LINQ) when working with collections to write concise and expressive code for data manipulation.

Top comments (0)