Edit

Share via


What's new in C# 15

C# 15 includes the following new features. You can try these features using the latest Visual Studio 2026 version or the .NET 11 preview SDK:

C# 15 is the latest C# release. C# 15 is supported on .NET 11. For more information, see C# language versioning.

You can download the latest .NET 11 preview SDK from the .NET downloads page. You can also download Visual Studio 2026 insiders, which includes the .NET 11 preview SDK.

New features are added to the "What's new in C#" page when they're available in public preview releases. The working set section of the roslyn feature status page tracks when upcoming features are merged into the main branch.

You can find any breaking changes introduced in C# 15 in our article on breaking changes.

Note

We're interested in your feedback on these features. If you find issues with any of these new features, create a new issue in the dotnet/roslyn repository.

Collection expression arguments

You can pass arguments to the underlying collection's constructor or factory method by using a with(...) element as the first element in a collection expression. This feature enables you to specify capacity, comparers, or other constructor parameters directly within the collection expression syntax.

The following example shows how to pass a capacity argument to a List<T> constructor and a comparer to a HashSet<T>:

string[] values = ["one", "two", "three"];

// Pass capacity argument to List<T> constructor
List<string> names = [with(capacity: values.Length * 2), .. values];

// Pass comparer argument to HashSet<T> constructor
HashSet<string> set = [with(StringComparer.OrdinalIgnoreCase), "Hello", "HELLO", "hello"];
// set contains only one element because all strings are equal with OrdinalIgnoreCase

You can learn more about collection expression arguments in the language reference article on collection expressions or the feature specification. For information on using collection expression arguments in collection initializers, see Object and Collection Initializers.