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.

listen Print view
Traffic sign with C#

(Image: Pincasso/Shutterstock)

2 min. read
By
  • 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>.

The Dotnet Doctor – Holger Schwichtenberg
Der Dotnet-Doktor – Holger Schwichtenberg

Dr. Holger Schwichtenberg is the technical director of the expert network www.IT-Visions.de, which supports numerous medium-sized and large companies with consulting and training services as well as software development, drawing on the expertise of 53 renowned experts. Thanks to his appearances at numerous national and international conferences, as well as more than 90 specialist books and over 1,500 specialist articles, Holger Schwichtenberg is one of the best-known experts for .NET and web technologies in Germany.

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)

Don't miss any news – follow us on Facebook, LinkedIn or Mastodon.

This article was originally published in German. It was translated with technical assistance and editorially reviewed before publication.