Here is the link.
C# version 9
Released November 2020
C# 9 was released with .NET 5. It's the default language version for any assembly that targets the .NET 5 release. It contains the following new and enhanced features:
- Records
- Init only setters
- Top-level statements
- Pattern matching enhancements: relational patterns and logical patterns
- Performance and interop
- Fit and finish features
C# 9 continues three of the themes from previous releases: removing ceremony, separating data from algorithms, and providing more patterns in more places.
Top level statements means your main program is simpler to read. There's less need for ceremony: a namespace, a Program class, and static void Main() are all unnecessary.
The introduction of records provides a concise syntax for reference types that follow value semantics for equality. You use these types to define data containers that typically define minimal behavior. Init-only setters provide the capability for nondestructive mutation (with expressions) in records. C# 9 also adds covariant return types so that derived records can override virtual methods and return a type derived from the base method's return type.
The pattern matching capabilities expanded in several ways. Numeric types now support range patterns. Patterns can be combined using and, or, and not patterns. Parentheses can be added to clarify more complex patterns:
C# 9 includes new pattern matching improvements:
- Type patterns match an object matches a particular type
- Parenthesized patterns enforce or emphasize the precedence of pattern combinations
- Conjunctive
andpatterns require both patterns to match - Disjunctive
orpatterns require either pattern to match - Negated
notpatterns require that a pattern doesn't match - Relational patterns require the input be less than, greater than, less than or equal, or greater than or equal to a given constant
No comments:
Post a Comment