- Mahesh Chand
- Mar 12, 2023
If you’re using the latest version of Visual Studio 2019, C#, you may not see the option to change the C# language version of your project. This is a new change in Visual Studio 2019/.NET Core 3.0. The new C# compiler chooses the default version based on your .NET target framework selected for your project in Visual Studio.
The compiler determines a default language based on the following rules:
Target framework version C# language version default
.NET Core3.xC# 8.0
.NET Core2.xC# 7.3
.NET FrameworkallC# 7.3
Note: If you’re using a previous version of Visual Studio, you’ve an option to select a language version up to C# 7.3.
C# 8.0 is the latest version of C# language. C# 8.0 introduces several new features. To learn more about these features, visit https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8
Can I change the default C# version?
Yes, you may.
If you open your .csproj project file in Notepad or any text editor, you can add a new property group and set the LangVersion value to specify the language version your project will use. The default proj file looks like the following in XML.
<ProjectSdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>netcoreapp3.0</TargetFramework></PropertyGroup></Project>The<ProjectSdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>netcoreapp3.0</TargetFramework></PropertyGroup><PropertyGroup><LangVersion>8.0</LangVersion></PropertyGroup></Project>
The LangVersion value can be one of the following:
preview
latest
latestMajor
8.0
7.3
7.2
7.1
7, 6, 5, 4, and 3