Similar to Does C# 8 support the .NET Framework?
I know that it's officially unsupported, but what features in C# 9 are available when using the .Net Framework (4.8)?
Features from -- https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history#c-version-9
- Records
- Init only setters
- Top-level statements
- Pattern matching enhancements
- Performance and interop
- Native sized integers
- Function pointers
- Suppress emitting localsinit flag
- Fit and finish features
- Target-typed new expressions
- static anonymous functions
- Target-typed conditional expressions
- Covariant return types
- Extension GetEnumerator support for foreach loops
- Lambda discard parameters
- Attributes on local functions
- Support for code generators
- Module initializers
- New features for partial methods
To the best of my knowledge this is what is done by the compiler, and what requires runtime support (i.e. will not run on .net framework, requires .net core)
C# 9
- Records (compiler only for .NET 4.0+, earlier versions would require additional work)
- init only setters (compiler, but needs class IsExternalInit)
- Top-level statements (compiler)
- Pattern matching enhancements (compiler)
- Native sized integers (eg nint and nuint, compiler)
- Function pointers (runtime I believe, wasn't able to verify)
- Suppress emitting localsinit flag (compiler, but needs class SkipLocalsInitAttribute)
- Target-typed new expressions (compiler)
- Static anonymous functions (compiler)
- Target-Typed Conditional Expression (compiler)
- Covariant return types (runtime)
- Extension GetEnumerator support for foreach loops (compiler, was already in VB)
- Lambda discard parameters (compiler)
- Attributes on local functions (compiler, can be used for debug only static functions)
- Support for code generators (compiler and ide)
- Module initializers (compiler, needs class ModuleInitializerAttribute)
- Extending Partial Methods (compiler)