↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Top 10 Mistakes that C# Programmers Make

The article collects ten common mistakes C# programmers make and explains why they happen. It focuses on language details and runtime behavior that can lead to wrong assumptions, unexpected results, and harder debugging.

Reading notes
#

  • C# is a strongly typed language on the CLR, and its type checking can catch many errors early, but programmers can still lose those benefits by using the language carelessly.
  • Value types and reference types behave differently, so assigning and modifying objects can produce surprising results if you do not know which kind of type you are using.
  • Uninitialized value types do not become null; they take a default value, so null checks can be misleading.
  • String comparison should be explicit, with Equals and a StringComparison value, because different comparison modes can produce different results.
  • LINQ can replace iterative collection manipulation, but performance trade-offs may still matter.
  • The result of a LINQ query can change depending on the underlying objects, such as in-memory collections versus DbSet data translated to SQL.
  • Extension methods are static methods brought into scope through using and marked by a this parameter on the first argument.
  • Choosing the right collection type matters for performance and type safety, and generic collections are usually preferable to non-generic ones.
  • Objects that wrap resources should be disposed deterministically, and using ensures Dispose() is called when a block ends.
  • Sometimes the exception-throwing form of an operation is the right choice, especially when failure should be surfaced immediately.
  • Compiler warnings should be fixed instead of ignored, because they can point to real defects even when the program still runs.