-
Notifications
You must be signed in to change notification settings - Fork 4.9k
[release-notes] C# in .NET 11 RC 1 #10547
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
danroth27
wants to merge
1
commit into
release-notes/11.0-rc1
Choose a base branch
from
release-notes/11.0-rc1-csharp
base: release-notes/11.0-rc1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+84
−0
Draft
Changes from all commits
Commits
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,84 @@ | ||
| # C# in .NET 11 RC 1 - Release Notes | ||
|
|
||
| .NET 11 RC 1 establishes C# 15 as the default language version and includes the | ||
| following C# updates: | ||
|
|
||
| - [C# 15 stabilizes unions and other language features](#c-15-stabilizes-unions-and-other-language-features) | ||
| - [Unsafe Evolution refinements](#unsafe-evolution-refinements) | ||
|
|
||
| C# updates: | ||
|
|
||
| - [What's new in C# 15](https://learn.microsoft.com/dotnet/csharp/whats-new/csharp-15) | ||
|
|
||
| ## C# 15 stabilizes unions and other language features | ||
|
|
||
| C# 15 is now selected by default for projects targeting .NET 11 | ||
| ([dotnet/roslyn #84799](https://github.com/dotnet/roslyn/pull/84799)). The | ||
| language version stabilizes the features introduced during the .NET 11 preview | ||
| cycle: collection expression arguments, union types, non-virtual static | ||
| interface members, closed class hierarchies, labeled `break` and `continue`, | ||
| and extension indexers. | ||
|
|
||
| For example, union types no longer require `<LangVersion>preview</LangVersion>`: | ||
|
|
||
| ```csharp | ||
| public record Success(string Message); | ||
| public record Failure(int ErrorCode); | ||
|
|
||
| public union Result(Success, Failure); | ||
|
|
||
| static string Describe(Result result) => result switch | ||
| { | ||
| Success(var message) => message, | ||
| Failure(var errorCode) => $"Error {errorCode}" | ||
| }; | ||
| ``` | ||
|
|
||
| The compiler and Roslyn APIs also use the final `CSharp15` language-version | ||
| names, and `ITypeSymbol.UnionCaseTypes` exposes the cases of a union to analyzers | ||
| and other compiler-based tools | ||
| ([dotnet/roslyn #84707](https://github.com/dotnet/roslyn/pull/84707)). | ||
|
|
||
| ## Unsafe Evolution refinements | ||
|
|
||
| > This is a preview feature for .NET 11. | ||
|
|
||
| Unsafe Evolution remains independent of C# 15 and still requires | ||
| `<LangVersion>preview</LangVersion>`. RC 1 completes several user-facing rules: | ||
|
|
||
| - `await` is allowed inside an `unsafe` context | ||
| ([dotnet/roslyn #84616](https://github.com/dotnet/roslyn/pull/84616)). | ||
| - `safe` can be applied anywhere that `unsafe` could mark a declaration as | ||
| *requires-unsafe*. This supports generated declarations such as | ||
| `LibraryImport` methods, even when `safe` has no other effect | ||
| ([dotnet/roslyn #84602](https://github.com/dotnet/roslyn/pull/84602)). | ||
| - `unsafe` on delegates, static constructors, destructors, and type | ||
| declarations is now an error because it no longer establishes a meaningful | ||
| unsafe context | ||
| ([dotnet/roslyn #84378](https://github.com/dotnet/roslyn/pull/84378)). | ||
| - Unsafe Evolution diagnostics are now reported consistently in the IDE | ||
| ([dotnet/roslyn #84603](https://github.com/dotnet/roslyn/pull/84603)). | ||
|
|
||
| ```csharp | ||
| unsafe async Task<int> ReadAsync() | ||
| { | ||
| int* value = stackalloc int[1]; | ||
| *value = 42; | ||
| int result = *value; | ||
| await Task.Yield(); | ||
| return result; | ||
| } | ||
|
|
||
| [LibraryImport("native")] | ||
| internal static safe partial int GetValue(); | ||
| ``` | ||
|
|
||
| Roslyn also exposes the final approved symbol API for determining whether a | ||
| declaration requires an unsafe context | ||
| ([dotnet/roslyn #84674](https://github.com/dotnet/roslyn/pull/84674), | ||
| [dotnet/roslyn #84784](https://github.com/dotnet/roslyn/pull/84784)). | ||
|
|
||
| <!-- Filtered features (significant engineering work, but not shipped in RC 1): | ||
| - Sonic declaration/implementation split: the merge and dependent work were | ||
| reverted by dotnet/roslyn #84831, so no Sonic feature is documented here. | ||
| --> | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this example is going to work under unsafe evolution. The
unsafeon the method signature no longer introduces anunsafecontext in the method body, hence this pointer dereference will report an error.Unless this example is supposed to be for the legacy memory safety rules, but that's unclear.