Microsoft is doubling down in the evolution of the C# language. They released C# 8.0 last year with many new features, namely the long-awaited nullable reference types.
For more information, you can read my complete coverage of the C# 8.0 features
Not even a few months have passed, and there's already a preview of C# 9.0 in the making. You can already play with it today!
New features in C# 9.0
- Top-Level programs
- Init-only properties
- Records and With-expressions
- Improved pattern matching
- Target-typed expression
- Simplified Null Validation (post coming soon)
- Primary Constructors
- Discriminated Unions (post coming soon)
Install the preview
To try out those features, you need to follow a few steps.
-
Download and install the latest SDK (v5.0.100-preview.7 at the time of this writing)
-
Open the
.csproj
in which you want to enable the C# 9.0 features' support and add<LangVersion>preview</LangVersion>
.
e.g.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>preview</LangVersion>
</PropertyGroup>
</Project>
- Have fun!
Wrapping up
C# 9.0 is evolving quickly. To keep up with the upcoming announcements, you can :
- Follow my blog RSS or subscribe down below 👇
- Look at the code samples I built
- Refer to the official GitHub documentation about C# 9.0 Language Feature status and the C# 9.0 Milestone