The best practice is a **_method _**or **_technique _**that has been generally accepted as **_superior _**to any alternatives because it produces results that are superior to those achieved by other means or because it has become a standard way of doing things, e.g., a standard way of complying with legal or ethical requirements.

Best Practices Help you by:

  • Understand the code quickly.
  • Facilitate copying, changing, and maintaining the code.

1. Naming and handling classes

The **benefits **of proper class naming and naming conventions:

  • You know what to expect from a certain class without looking at code or documentation, even if you aren’t the person who created it or if it was written a long time ago.
  • It’s easy to search and navigate a codebase.
  • It’s easier to talk to your team when discussing problems/improvements.
  • It makes onboarding newcomers easier, quicker, and less confusing.

Names Rules

  1. Choose descriptive and unambiguous names.
  2. Make a meaningful distinction.
  3. Use pronounceable names.
  4. Use searchable names.
  5. Replace magic numbers with named constants.
  6. Avoid encodings. Don’t append prefixes or type information.

2. Naming and handling methods, fields, and properties

Method Overloading:

**Overloading **is used (recommended) when multiple methods have the same purpose but there is more than one way to start it.

Methods rules:

  1. Small.
  2. Do one thing.
  3. Use descriptive names.
  4. Prefer fewer arguments.
  5. Have no side effects.
  6. Don’t use flag arguments. Split method into several independent methods that can be called from the client without the flag.

#web-development #dotnet #programming #c#

Best Practices for C# Developers
1.50 GEEK