The C# version is typically determined by the target framework because the compiler automatically selects the default C# version based on the framework version of the project.
Target framework | Version | C# language version default |
---|---|---|
.NET | 9.x | C# 13 |
.NET | 8.x | C# 12 |
.NET | 7.x | C# 11 |
.NET | 6.x | C# 10 |
.NET | 5.x | C# 9.0 |
.NET Core | 3.x | C# 8.0 |
.NET Core | 2.x | C# 7.3 |
.NET Standard | 2.1 | C# 8.0 |
.NET Standard | 2.0 | C# 7.3 |
.NET Standard | 1.x | C# 7.3 |
.NET Framework | all | C# 7.3 |
While the framework version typically determines the C# version, it is possible to override this default behavior by explicitly setting the C# version in the project file (.csproj
). This gives developers control to use an older or newer version of the language, as long as the compiler supports it.
You can set the language version in your project file. For example, if you explicitly want access to preview features, add this:
<PropertyGroup>
<LangVersion>preview</LangVersion>
</PropertyGroup>
You can also set the language version explicitly.
<PropertyGroup>
<LangVersion>11.0</LangVersion> <!-- Force C# 11.0 -->
</PropertyGroup>
The currently active .NET SDK version
The following command displays the currently active .NET SDK version on your system.
dotnet --version
The location of the .NET SDK
The following command will display a list of all installed .NET SDK versions along with the paths where they are located.
dotnet --list-sdks