This page shows the source for this entry, with WebCore formatting language tags and attributes highlighted.
Title
C# 13 improvements
Description
The final document of <a href="https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-13" author="" source="Microsoft Learn">What's new in C# 13</a> is available. There are no major changes for most end users; the changes listed are interested for library and framework developers---especially those interested in writing highly performant code, e.g., Microsoft in its BCL and ASP.NET.
<ol>
Completely unsurprisingly, the <c>params</c> keyword now also applies to <c>IEnumerable<t></c> (as well as many descendants) as well as <c>Span<t></c> and <c>ReadOnlySpan<t></c>.
There's now an official <c>Lock</c> object that, when used instead of the standard <c>object</c>, can lead to more efficient locking code. The .NET runtime and BCL have already starting using this <c>ref struct</c> everywhere.
I am not kidding when I say that the third "feature" in the list is that <c>\e</c> is now an accepted escape sequence in all strings. It represents <c>ESCAPE</c>. Um, ok.
Method group and method-group calculation has been improved to more closely follow that for overload resolution, allowing Roslyn to better determine a unique type and to extend where <c>var</c> can be safely used.
You can now use the "from the end" index operator, <c>^</c> in object and collection initializer expressions. Again, this is an improvement that seems like it makes it easier to write input arrays for numeric (data analysis) or tokenizing (LLM) operations.
<div><bq>In C# 13, async methods can declare ref local variables, or local variables of a <c>ref struct</c> type. However, those variables can't be accessed across an await boundary. Neither can they be accessed across a yield return boundary.
[...] You can safely use types like <c>System.ReadOnlySpan<t></c> [...]
In the same fashion, C# 13 allows <c>unsafe</c> contexts in iterator methods. However, all <c>yield return</c> and <c>yield break</c> statements must be in safe contexts.</bq></div>
<c>ref structs</c> can now implement interfaces but it's hard to see the utility because <iq>[t]o ensure ref safety rules, a ref struct type can't be converted to an interface type.</iq> Um, ok?
The language now supports the <c>allows ref struct</c> (anti-)generic constraint. <iq>This enables types such as <c>System.Span<t></c> and <c>System.ReadOnlySpan<t></c> to be used with generic algorithms [...]</iq> The compiler ensures that the generic code complies with all the rules implied by allowing this more specialized construct.
Finally, <iq>you can declare partial properties and partial indexers</iq>. Expanding support for <c>partial</c> enables more flexibility in code produced by source generators.
</ol>