Using C# 9.0 with Any Project on Visual Studio 2019
c#Even though Visual Studio 2019 comes with C# 9.0, not all new projects will start with C# 9.0. For example, if you start a .NET Core 3.1 project, it will default to C# 8.0. However, it is possible to change it to use C# 9.0 having to install anything else.
Framework | Version | C# Default Version |
---|---|---|
.NET | 5.x | 9.0 |
.NET Core | 3.x | 8.0 |
.NET Core | 2.x | 7.3 |
.NET Framework | any | 7.3 |
Reference: MS Docs
If you start a .NET 5.0 project, you don't need to change anything, otherwise, if you want to change the version, follow these steps:
- Right-click on your Project in the Solution Explorer, click Unload Project.
- In the .csproj file that shows up, add this line to the
<PropertyGroup>
:
<LangVersion>9</LangVersion>
- Right-click on your Project in the Solution and click Reload Project