Repository navigation
[release-notes] C# in .NET 11 Preview 6 #10460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BillWagner
merged 2 commits into
release-notes/11.0-preview6
from
release-notes/11.0-preview6-csharp
Jul 10, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <!-- Verified by compiling against the .NET 11 Preview 6 SDK (11.0.100-preview.6) with LangVersion=preview --> | ||
| # C# in .NET 11 Preview 6 - Release Notes | ||
|
|
||
| .NET 11 Preview 6 includes the following C# language and compiler updates: | ||
|
|
||
| - [Extension indexers](#extension-indexers) | ||
| - [Unions ship their support types in the box](#unions-ship-their-support-types-in-the-box) | ||
|
|
||
| C# updates: | ||
|
|
||
| - [What's new in C# 15](https://learn.microsoft.com/dotnet/csharp/whats-new/csharp-15) | ||
|
|
||
| ## Extension indexers | ||
|
|
||
| Extension members now include **indexers**, so you can add `this[...]` access to a type from an `extension` block ([dotnet/roslyn #81607](https://github.com/dotnet/roslyn/pull/81607)). This rounds out the extension members feature introduced in .NET 10, which already supported extension methods and properties. | ||
|
|
||
| An extension indexer is declared like an instance indexer inside an `extension` block. The following example adds from-the-end indexing to `IReadOnlyList<T>`, which defines `this[int]` but not `this[Index]`: | ||
|
|
||
| ```csharp | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| IReadOnlyList<string> log = ["start", "work", "done"]; | ||
|
|
||
| Console.WriteLine(log[^1]); // done | ||
| Console.WriteLine(log[^2]); // work | ||
|
|
||
| public static class ReadOnlyListExtensions | ||
| { | ||
| extension<T>(IReadOnlyList<T> list) | ||
| { | ||
| public T this[Index index] => list[index.GetOffset(list.Count)]; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Extension indexers follow the same resolution rules as other extension members: they're only considered when no applicable instance indexer is found. They support multiple parameters, `get`/`set` accessors, and work in list patterns. Extension indexers remain a preview feature, so enable `<LangVersion>preview</LangVersion>` to use them. | ||
|
|
||
| ## Unions ship their support types in the box | ||
|
|
||
| Preview 5 introduced `union` declarations and union patterns, but projects had to hand-author the compiler support types (`UnionAttribute` and `IUnion`). In Preview 6, those types ship in the framework as `System.Runtime.CompilerServices.UnionAttribute` and `System.Runtime.CompilerServices.IUnion`, so a `union` now compiles with no extra boilerplate: | ||
|
|
||
| ```csharp | ||
| public record class Dog(string Name); | ||
| public record class Cat(int Lives); | ||
|
|
||
| public union Pet(Dog, Cat); | ||
|
|
||
| static string Describe(Pet pet) => pet switch | ||
| { | ||
| Dog(var name) => $"dog: {name}", | ||
| Cat(var lives) => $"cat: {lives}" | ||
| }; | ||
| ``` | ||
|
|
||
| `System.Text.Json` now serializes union values, writing the active case directly ([dotnet/runtime #128162](https://github.com/dotnet/runtime/pull/128162)). Serializing a `Pet` that holds a `Dog("Rex")` produces `{"Name":"Rex"}`. See the [.NET Libraries release notes](./libraries.md) for the serialization details and the [ASP.NET Core release notes](./aspnetcore.md) for how unions appear in OpenAPI documents. | ||
|
|
||
| Preview 6 also refines the language rules for unions: | ||
|
|
||
| - A `union` declaration can use a non-public constructor that takes a single parameter ([dotnet/roslyn #83788](https://github.com/dotnet/roslyn/pull/83788)). | ||
| - A `not` pattern applies to the incoming union value rather than its contained value ([dotnet/roslyn #83904](https://github.com/dotnet/roslyn/pull/83904)). | ||
| - Custom union types support inheritance of their generated `Create` methods ([dotnet/roslyn #83991](https://github.com/dotnet/roslyn/pull/83991)). | ||
| - The compiler reports a clear error when a custom `union` declaration is missing the minimal set of required APIs ([dotnet/roslyn #83813](https://github.com/dotnet/roslyn/pull/83813)). | ||
|
|
||
| Unions remain a preview feature; enable `<LangVersion>preview</LangVersion>` to try them, and expect the surface to keep evolving before the feature ships. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.