Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C# 9 support the .NET Framework? [closed]

Tags:

c#

c#-9.0

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
like image 936
jmoreno Avatar asked Oct 16 '25 03:10

jmoreno


1 Answers

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)
like image 197
jmoreno Avatar answered Oct 18 '25 17:10

jmoreno



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!