8 Guidelines to Write Readable Code in C# With .NET 6 | by Tobias Streng | Feb, 2022

Improve your C# code even further with these tips

Tobias Streng
Photo by James Harrison on Unsplash

1. Avoid “Else”

Examples of avoiding else

2. Avoid high Cyclomatic Complexity

Use Interfaces

3. Avoid too much identification-levels

4. Avoid Loops by Mastering Linq

Replace Loops with Linq-Queries

5. Extract and name your methods

Extract Methods and name them well

6. Break and Indent your code

Break before a point
Break arguments and add names

7. Use short syntax

Short If
Short Null Checking
String Interpolation
Pattern matching
Expression Bodies
Record Types

8. Global Usings and File-Scoped Namespaces

File-Scoped Namespace
Result of global uses or implicit uses

Leave a Comment