Build1 publisher3 min readPublished
Trying C#'s .NET 11 features means running RC1 in preview mode
Most of the code in a dev.to tour of four C# features needs .NET 11 RC1 with preview mode switched on in the project file. Its author adds that the dotnet tool cannot report the matching C# version, and rates unmeasured compiler optimizations as the best change.
The Engineer · Build desk

What happened
- Most of the post's sample code needs the .NET 11.0-rc1 SDK, a project configured to target it, and preview mode enabled.
- The new field keyword lets a property setter validate a value and assign the compiler-synthesized backing field without declaring one.
- Null-conditional assignment lets code put ?. on the left of an equals sign, so the write happens only when the object is not null.
Compiled by The EngineerSomething wrong?How this is made
Why it matters
- constraint Adopting these features on RC1 today puts a preview opt-in into the build file of every project that uses them.
- cost The performance case for moving to .NET 11 has to come from a team's own before-and-after builds, because the post's optimization claim comes without figures.
- capability Marking a base class closed lets a type switch drop its default arm and rely on the compiler's coverage check instead.
The version question first shows up in the project file. It pins `<TargetFramework>net11.0</TargetFramework>` and adds `<Preview>enable</Preview>` [3]. No C# language version appears anywhere in it [3]. The author asks which C# version corresponds to these .NET releases. The answer given is that there is no simple one, and that the dotnet tool cannot produce it [4].
That leaves a team two settings it can actually see when planning an upgrade: the framework moniker and the preview switch. The language a developer gets is whatever the RC1 compiler accepts with preview on. Most of the post's samples need exactly that combination: the 11.0-rc1 SDK, a project configured for it, and preview enabled [2]. I think that is fine for a spike branch. On a shared codebase, the upgrade ticket should name the SDK build, because the tooling will not report the language version back [4]. The author also notes growing calls for a period of stability after so much change, and adds that Microsoft has the last word [7].
The post leads with code nobody reads. "Los mejores cambios son los que no se ven," the author wrote, calling the best changes the ones you don't see [5]. The credit goes to Microsoft engineers who, the post says, are aggressively optimizing compiler-generated code to make it as fast as possible [6]. The post does not include a benchmark or name a specific optimization [13]. For that claim to transfer to a given service, its hot paths would have to be ones where the compiler's output actually changed. The way to find out is to build the same code on both SDKs and profile it.
The visible features are smaller and easier to judge. `field` is the one I would adopt first. The author's validating setter previously needed a declared `private int x` to write into [9]. With `field`, the setter checks `value < 0`, throws on a negative, and otherwise assigns to the compiler-synthesized backing field [9]. The check stays in the setter and the extra member goes away.
Null-conditional assignment puts `?.` on the left of an assignment. `person?.Name = "The One";` writes only when `person` is not null [10]. Index-from-end uses `^` where other languages use a negative index. The example fills a ten-element array from `buffer[^1]` to `buffer[^10]` with 11 through 20, then prints 20 down to 11 [8].
`closed` does the most for correctness. Marking `Person` closed limits it to the derived classes the author declares, here `Employee` and `Retired` [11]. The `IncomeLabel` switch then matches those two types with no default arm, and the compiler can check that every case is handled [11]. Of the four features in the post [12], it is the only one that gives the compiler a new check to run.
What to watch
- Whether Microsoft publishes a C# version mapping for .NET 11 at general availability, or the dotnet tool gains a way to report it.
- Published before-and-after measurements of identical code built on .NET 11 and the current release, which would test the optimization claim.
- Whether closed classes and null-conditional assignment still require the preview switch once .NET 11 leaves release candidate.