New in .NET 10.0 [3]: C# 14.0
C# 14.0 ships with .NET 10.0. However, you can still use some C# 14.0 language features in older .NET versions.
(Image: Pincasso/Shutterstock)
- Dr. Holger Schwichtenberg
In a .NET 10.0 project (project setting in .csproj file: <TargetFramework>net10.0</TargetFramework>), C# language version 14.0 is the automatically set default, even without an additional tag <LangVersion>.
C# 14.0 is officially supported by Microsoft only from .NET 10.0 onwards. Microsoft's Learn site states: “C# 14.0 is supported only on .NET 10 and newer versions.”
However, developers can use some (but not all!) C# 14.0 language features in older .NET versions, including .NET Framework, .NET Core, and Xamarin, at their own risk. To achieve this, you need to increase the <LangVersion> in the project file (.csproj) to “14.0”:
<PropertyGroup>
<TargetFramework>.net8.0</TargetFramework>
<LangVersion>14.0</LangVersion>
</PropertyGroup>
Please note, however, that there is no technical support from Microsoft for the use of C# 14.0 language features in .NET versions before 10.0. In case of problems, you cannot use your support contract to ask Microsoft for help. Nevertheless, using higher C# versions in older .NET projects is common and trouble-free practice in some companies.
Videos by heise
Compared to version 13.0, eight significant new features have appeared in C# 14.0 (which will be presented in this blog series in the coming weeks):
- New operator overloads for +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=, and >>>
- Extension blocks with the keyword
extension - Semi-auto properties with the keyword
field(these already existed in C# 13.0, but experimentally) - Partial constructors and partial events
- Null-conditional assignment
- Simplification for
nameof()with generic types - Simplifications for lambda expressions
- More conversions for spans
Of the new language features in .NET 10.0 mentioned above, all but one work in older .NET versions as well, provided you set <LangVersion>latest</LangVersion> in the project file. The exception is the new operator overloads. These will be covered in the next article in this series.
(mki)