In a C# .NET Core application, you can change the C# language version by modifying the .csproj file or configuring your IDE settings.
1️⃣ Change Language Version in .csproj File (Recommended)
- Open your
.csprojfile in a text editor or IDE. - Add the
<LangVersion>element inside<PropertyGroup>, like this: xmlCopyEdit<PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <LangVersion>latest</LangVersion> <!-- Use latest C# version --> </PropertyGroup> - Save the file and rebuild the project:
dotnet build
Available Language Versions
You can specify a specific C# version instead of latest. Here are some options:
| Version | LangVersion Value |
|---|---|
| C# 12 (Latest) | latest |
| C# 11 | 11 |
| C# 10 | 10 |
| C# 9 | 9 |
| C# 8 | 8 |
| C# 7.3 | 7.3 |
| Default Version | default |
2️⃣ Change Language Version in Visual Studio (For .NET Core)
If you are using Visual Studio, you can change the C# version in project settings:
- Right-click the project in Solution Explorer → Click Properties.
- Navigate to Build → Click Advanced.
- Locate the Language Version dropdown.
- Select the desired C# version (e.g.,
C# 11,latest). - Save and rebuild the project.
3️⃣ Change Language Version via CLI (global.json)
If you have multiple .NET SDKs installed, your project might use an older C# version.
To force it to use a specific version, create a global.json file:
dotnet new globaljson --sdk-version 8.0.100
Or manually create a global.json file in your project folder:
{
"sdk": {
"version": "8.0.100"
}
}
4️⃣ Check Current C# Version
To verify the C# language version in your project, run:
dotnet --version
If you want to check which version of C# your project is using, you can add the following code inside your application:
Console.WriteLine($"C# Version: {System.Runtime.CompilerServices.RuntimeFeature.IsSupported(\"C#12\")}");
Final Step: Rebuild the Project
Once you’ve updated the language version, rebuild your project:
dotnet build
