C# Modernization Overview
Version map
Section titled “Version map”- C# 8 — nullable reference types, switch expressions, property patterns, using declarations, indices and ranges, async streams
- C# 9 — records, init-only setters, target-typed
new, relational and logical patterns, top-level statements - C# 10 — file-scoped namespaces, global usings, record structs, extended property patterns,
CallerArgumentExpression - C# 11 — raw string literals, required members, list patterns, generic attributes, UTF-8 string literals
- C# 12 — primary constructors, collection expressions, inline arrays, alias any type,
ref readonlyparameters - C# 13 — params collections, new
locksemantics, method group natural type improvements, partial properties and indexers,ref structinterface support - C# 14 — extension members,
fieldkeyword for field-backed properties, null-conditional assignment, first-classSpan<T>/ReadOnlySpan<T>conversions
Modernization Guidelines
Section titled “Modernization Guidelines”When modernizing .NET code, start with these new language features:
- nullable reference types
- pattern matching and switch expressions
- records,
init, andrequired - file-scoped namespaces and global usings
- raw string literals
- collection expressions
- selected performance-oriented features such as spans and params collections where they provide measurable value
Adoption order
Section titled “Adoption order”1. Safety and correctness
Section titled “1. Safety and correctness”- enable nullable reference types
- replace brittle null handling with explicit intent
- modernize branching logic with pattern matching
2. Data and API design
Section titled “2. Data and API design”- use records for value-like data models
- use
initandrequiredwhere immutable initialization is the goal
3. Readability and maintainability
Section titled “3. Readability and maintainability”- introduce file-scoped namespaces
- add global usings carefully
- replace noisy string escaping with raw string literals
4. Targeted performance improvements
Section titled “4. Targeted performance improvements”- use ranges, spans, and params collections where they remove allocations or simplify hot-path code
- measure before optimizing