1
0
mirror of synced 2025-12-19 18:06:02 -05:00
Files
core/release-notes/10.0/preview/preview3/csharp.md
James Montemagno d136e6ab76 .NET 10 - Preview 3 (#9817)
* stage P3

* cleanup

* efcore doc updates for preview 3

* .NET MAUI in .NET 10 Preview 3 (#9826)

* .NET MAUI in .NET 10 Preview 3

* Update .NET MAUI release notes for preview 3

* .NET 10 P3 - SDK Notes (#9822)

* SDK Start

* Add first draft of SDK features for p3

* Update release-notes/10.0/preview/preview3/sdk.md

* Update release-notes/10.0/preview/preview3/sdk.md

* Update release-notes/10.0/preview/preview3/sdk.md

Co-authored-by: Youssef Victor <youssefvictor00@gmail.com>

* Update release-notes/10.0/preview/preview3/sdk.md

Co-authored-by: Youssef Victor <youssefvictor00@gmail.com>

---------

Co-authored-by: Chet Husk <chusk3@gmail.com>
Co-authored-by: Chet Husk <baronfel@users.noreply.github.com>
Co-authored-by: Youssef Victor <youssefvictor00@gmail.com>

* .NET 10 Preview 3 - Runtime (#9823)

* .NET 10 P3 Runtime

* Add JIT notes

* Fix indentation

* Feedback

---------

Co-authored-by: Aman Khalid (from Dev Box) <amankhalid@microsoft.com>

* Add ASP.NET Core release notes for .NET 10 Preview 3 (#9835)

* Add ASP.NET Core release notes for .NET 10 Preview 3

* Add server-sent events

* Add declarative state persistence

* Add OpenAPI template option

* Add min API validation

* Add built-time env for Blazor WebAssembly

* Apply edits

* Apply suggestions from PR review

Co-authored-by: Wade Pickett <wpickett@microsoft.com>

* Update release-notes/10.0/preview/preview3/aspnetcore.md

Co-authored-by: Wade Pickett <wpickett@microsoft.com>

* Update release-notes/10.0/preview/preview3/aspnetcore.md

Co-authored-by: Wade Pickett <wpickett@microsoft.com>

* Update release-notes/10.0/preview/preview3/aspnetcore.md

Co-authored-by: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com>

* Update release-notes/10.0/preview/preview3/aspnetcore.md

Co-authored-by: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com>

* Update release-notes/10.0/preview/preview3/aspnetcore.md

* Update release-notes/10.0/preview/preview3/aspnetcore.md

Co-authored-by: Daniel Roth <daroth@microsoft.com>

---------

Co-authored-by: Mike Kistler <mikekistler@microsoft.com>
Co-authored-by: Wade Pickett <wpickett@microsoft.com>
Co-authored-by: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com>
Co-authored-by: Pavel Savara <pavelsavara@microsoft.com>

* Updates for P3 (#9831)

* .NET 10 P3 - Libraries (#9824)

* .NET 10 P3 - Libraries

* Introduce an AOT-Safe Constructor for ValidationContext

* Support for Telemetry Schema URLs in ActivitySource and Meter

* Byte-Level Support in BPE Tokenizer

* ML.NET notes

* Tensor update notes

---------

Co-authored-by: Tarek Mahmoud Sayed <10833894+tarekgh@users.noreply.github.com>
Co-authored-by: Michael Sharp <51342856+michaelgsharp@users.noreply.github.com>

* cleanup

* cleanup

* cleanup

* cleanup

* Initial draft of P3 release notes (#9832)

* cleanup

* cleanup

* Update release-notes/10.0/preview/preview3/csharp.md

Co-authored-by: Martin Costello <martin@martincostello.com>

* Update release-notes/10.0/preview/preview3/aspnetcore.md

Co-authored-by: Mike Kistler <mikekistler@microsoft.com>

* update code block

* Add global.json local sdk support details

* Added WPF notes (#9844)

* update readmes

* fix readme

* Updated 10.0.0-preview.3.md with content and Nuget list

* cleanup 1

* Implement feature X to enhance user experience and optimize performance

* Update release-notes/10.0/preview/preview3/10.0.0-preview.3.md

Co-authored-by: Martin Costello <martin@martincostello.com>

* Updated windowsdesktop Urls

* cleanup

* updat elinux

* udpated

* Fix table

---------

Co-authored-by: maumar <maumar@microsoft.com>
Co-authored-by: David Ortinau <david.ortinau@microsoft.com>
Co-authored-by: Chet Husk <chusk3@gmail.com>
Co-authored-by: Chet Husk <baronfel@users.noreply.github.com>
Co-authored-by: Youssef Victor <youssefvictor00@gmail.com>
Co-authored-by: Aman Khalid (from Dev Box) <amankhalid@microsoft.com>
Co-authored-by: Daniel Roth <daroth@microsoft.com>
Co-authored-by: Mike Kistler <mikekistler@microsoft.com>
Co-authored-by: Wade Pickett <wpickett@microsoft.com>
Co-authored-by: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com>
Co-authored-by: Pavel Savara <pavelsavara@microsoft.com>
Co-authored-by: Merrie McGaw <mmcgaw@microsoft.com>
Co-authored-by: Tarek Mahmoud Sayed <10833894+tarekgh@users.noreply.github.com>
Co-authored-by: Michael Sharp <51342856+michaelgsharp@users.noreply.github.com>
Co-authored-by: Kathleen Dollard <kdollard@microsoft.com>
Co-authored-by: Martin Costello <martin@martincostello.com>
Co-authored-by: Andy (Steve) De George <67293991+adegeo@users.noreply.github.com>
Co-authored-by: victorisr <victorisr@microsoft.com>
2025-04-10 13:03:15 -07:00

4.9 KiB
Raw Blame History

C# 14 updates in .NET 10 Preview 3 - Release Notes

Here's a summary of what's new in C# in this preview release:

C# 14 updates:

Extension members

Extensions just got even more powerful! In Preview 3, they now support static methods, instance properties, and static properties—expanding the capabilities you already know and love. And this is just the beginning—stay tuned for even more extension support in an upcoming release!

Expanding extensions to other member types has been a long-standing challenge, driven by two key questions: how to declare them effectively and how to resolve ambiguity when multiple matching signatures exist. Additionally, we aimed to seamlessly support the new syntax for instance members—ensuring that users of instance extension methods never have to worry about whether they were declared with the old or new syntax. After extensive development, were bringing these solutions to life!

Today you may have an extension method that follows the pattern:

public static class Extensions
{
    public static IEnumerable<int> WhereGreaterThan(this IEnumerable<int> source, int threshold) 
        => source.Where(x => x > threshold);
}

The receiver is the parameter prefaced by the this keyword - source in this case. Property declarations do not have a similar location to declare the receiver. Thus, C# 14 introduces extension blocks. These are blocks with a scope that exposes the receiver to its contained members. If we switch the WhereGreaterThan extension method to the new syntax and add an IsEmpty property the extension block would be:

public static class Extensions
{
    extension(IEnumerable<int> source) 
    {
        public IEnumerable<int> WhereGreaterThan(int threshold)
            => source.Where(x => x > threshold);

        public bool IsEmpty
            => !source.Any();
    }
}

To use these members, you just call them:

var list = new List<int> { 1, 2, 3, 4, 5 };
var large = list.WhereGreaterThan(3);
if (large.IsEmpty)
{
    Console.WriteLine("No large numbers");
}
else
{
    Console.WriteLine("Found large numbers");
}

Generics are supported and the resolution rules are the same as for extension methods. For example, you could make WhereGreaterThan and IsEmpty generic:

extension<T>(IEnumerable<T> source)
    where T : INumber<T>
{
    public IEnumerable<T> WhereGreaterThan(T threshold)
        => source.Where(x => x > threshold);

    public bool IsEmpty
        => !source.Any();
}

The constraint to INumber<T> allows the greater than operator to be used.

Static methods and properties don't have a receiver, so the extension block list the type without a parameter name:

extension<T>(List<T>)
{
    public static List<T> Create()
        => [];
}

Extension blocks can seamlessly coexist with the extension methods you have today. There's no requirement to switch to the new syntax - both execute in exactly the same way. Just add extension blocks to the static classes that contain your existing extension methods.

The choice is entirely yours. If you prefer to leave your existing extension methods untouched, you absolutely can. But if youd rather update your code for a consistent look and take advantage of the new syntax, that option is available too. And with tools like Visual Studio, converting to your preferred form has never been easier!

You'll see more extensions in upcoming previews, but we'd love to hear your feedback, so join the team and others in the community in the discussion Extensions.

Null-conditional assignment

Null-conditional assignment assigns a value to a property or field only if the containing instance exists. Imagine you have a code similar to:

public class Customer
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public class UpdateCustomer
{
    public static void UpdateAge(Customer? customer, int newAge)
    {
        if (customer is not null)
        {
            customer.Age = newAge;
        }
    }
}

You can simplify the UpdateAge method:

public static void UpdateAge(Customer? customer, int newAge)
{
    customer?.Age = newAge;
}

If the customer is not null, Age will be updated. If customer is null, nothing will happen.

The IDE will help you by recommending this change via a lightbulb.

We'd love your feedback on this feature so join us and others in the community in the discussion on Null-conditional assignment.