Let’s catch up with C#! Exciting new features in C# 9, 10, 11 and 12! - Filip Ekberg

Explore the latest features in C# 9-12, from primary constructors and pattern matching to collection expressions and raw string literals. Level up your C# coding skills!

Key takeaways
  • New C# features focus on improving performance, reducing allocations and making code more concise while maintaining readability

  • Primary constructors introduced in C# 12 allow declaring constructor parameters directly in the class declaration, reducing boilerplate code for data classes

  • Pattern matching enhancements across C# 9-12 provide more expressive ways to examine data and control flow, including list patterns, relational patterns and span patterns

  • Collection expressions and spread operators simplify working with arrays and collections while reducing memory allocations

  • Nullable reference types help catch potential null reference exceptions at compile time by adding static analysis

  • Record types introduced in C# 9 provide concise syntax for immutable data classes with value-based equality

  • UTF-8 string literals optimize string handling for web scenarios by avoiding UTF-16 conversions

  • Raw string literals (using “””) improve multiline string formatting for JSON, XML and SQL

  • Required properties ensure initialization of critical fields at object creation time

  • File-scoped namespaces and global using directives reduce code verbosity and improve organization