Skip to main content

C# 15.0

Release Date: November 10, 2026

C# 15 shipped on November 10, 2026 as part of the .NET 11 launch, and it is the default language version for any project that targets net11.0 with the .NET 11 SDK. This is a substantial language release: union types and closed hierarchies change how the compiler reasons about exhaustiveness, collection expressions finally accept constructor arguments, and extension indexers fill a long-standing gap in extension members.

Release Overview

VersionC# 15
Release dateNovember 10, 2026
Ships with.NET 11 SDK, Visual Studio 2026
Default forProjects targeting net11.0
Opt-inMemory safety preview feature only

The release notes describe C# 15 as the default language version for net11.0 projects. Everything below works under the default language version except the memory safety work, which still requires <LangVersion>preview</LangVersion> plus the updated memory safety rules feature flag.

Union Types

Union types are the headline feature. A union declares a value that can be one of several case types, and the compiler tracks the full set so switch expressions can be verified as exhaustive.

public record class Cat(string Name);
public record class Dog(string Name);
public record class Bird(string Name);

public union Pet(Cat, Dog, Bird);

Pet pet = new Dog("Rex");
string name = pet switch
{
    Dog d => d.Name,
    Cat c => c.Name,
    Bird b => b.Name,
};

Implicit conversions from each case type are generated for you. If a new case type is added later and a switch is not updated, the compiler reports the gap instead of silently falling through to a default arm.

Closed Hierarchies

The new closed modifier restricts derivation to the declaring assembly, which fixes the set of direct descendants at compile time. Because the compiler knows every direct descendant, a switch that handles each one is exhaustive without a default arm.

public closed record class GateState;
public record class Closed : GateState;
public record class Open(float Percent) : GateState;

string Describe(GateState state) => state switch
{
    Closed => "closed",
    Open(var percent) => $"{percent}% open",
};

Two details matter in practice. A closed class is implicitly abstract and cannot be combined with sealed, static, or an explicit abstract modifier. Derivation is also not transitive: a non-closed descendant of a closed class can still be derived from in other assemblies, so intermediate types must be marked closed as well if you want exhaustiveness checking to carry down the hierarchy.

Collection Expression Arguments

Collection expressions now accept a with(...) element as the first element. That element passes arguments to the underlying collection's constructor or factory method, so capacity, comparers, and other parameters can be specified inline instead of falling back to a constructor call.

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

List<string> names = [with(capacity: values.Length * 2), .. values];

HashSet<string> set = [with(StringComparer.OrdinalIgnoreCase), "Hello", "HELLO", "hello"];
// set contains one element, because all three strings compare equal

This removes a common reason to abandon collection expressions when a comparer or a known capacity was required.

Extension Indexers

Extension blocks can declare indexers starting in C# 15. Indexers are instance members, so the extension block must give its receiver a name.

public static class SequenceIndexer
{
    extension(IEnumerable<int> sequence)
    {
        public int this[int index] => sequence.ElementAt(index);
    }
}

IEnumerable<int> numbers = Enumerable.Range(1, 10);
int third = numbers[2];

Labeled break and continue

break and continue can now name a label on an enclosing construct. A labeled break exits the labeled loop instead of only the innermost one, which removes a frequent reason to introduce a boolean flag or extract a helper method in nested iteration code.

Static Interface Members and Memory Safety

Non-virtual static interface members can now be used on older runtimes, lifting a restriction that previously forced multi-targeting workarounds for libraries that wanted to expose static interface APIs.

The memory safety preview feature is separate and opt-in. It covers both syntax and pointer relaxations plus updated safety rules, and it requires the preview language version together with the updated-memory-safety-rules feature flag. Do not enable it in production projects until the rules stabilize, because the analysis can block code that compiles today.

Breaking Changes and Migration

Most of C# 15 is additive. Union types, closed hierarchies, extension indexers, collection expression arguments, and labeled jumps are new syntax and do not change the meaning of existing code. The areas to review before upgrading are the analyzer and compiler rule updates tied to the memory safety preview, plus the usual language version bump that comes with retargeting to net11.0.

Projects that cannot move to .NET 11 yet can still use the language by setting <LangVersion>15</LangVersion> on an existing target framework, as long as the runtime provides the required types. Union types and closed hierarchies depend on new compiler support, so verify the target framework before adopting them in a shared library.

How to Upgrade

  • Install the .NET 11 SDK (11.0.100 or later) or Visual Studio 2026.
  • Change the target framework to net11.0 to get C# 15 by default, or set <LangVersion>15</LangVersion> to opt in on an older target.
  • Run the full test suite and the analyzer pass. The compiler is stricter about exhaustiveness in switches over union and closed types.
  • Leave the memory safety preview feature off unless you are explicitly evaluating it.

C# 15 is available now with the .NET 11 SDK. The language reference documentation has dedicated pages for union types, the closed modifier, extension members, and collection expressions.

Sources

Other Versions

We use cookies for ads and analytics.