Extension members, the field keyword and several refinements to lambdas, spans and partial types.
This release added 9 features, each with a before-and-after example.
Features in C# 14.0
- Extension members - Add properties to existing classes just like extension methods.
- Field keyword - Reference the synthesized backing field of an auto property using the field keyword.
- File-based app directives - New preprocessor directives for configuring file-based apps.
- Implicit span conversions - Implicitly convert arrays and strings to spans without explicit casting.
- Null-conditional assignment - Conditionally assign values with
?.just like reading values. - Partial events and constructors - Allow constructors and events to be partially defined like partial methods and properties.
- Simple lambda parameters with modifiers - Use parameter modifiers without specifying types in simple lambda syntax.
- Unbound generic types and nameof - Use the
nameofkeyword with generic definitions. - User-defined compound assignment - Define custom behavior for compound assignment operators like += and -=.