#9499·csharplang

[Proposal]: Closed Hierarchies (VS 18.8, .NET 11)

Author: mattwarCreated Jun 30, 2025Updated Aug 12, 2026
LabelsProposal championImplemented Needs ECMA Spec

Closed Hierarchies

Summary

Allow a class to be declared closed. This prevents directly derived classes from being declared in a different assembly:

csharp
// Assembly 1
public closed record class GateState;
public record class Closed : GateState;
public record class Open(float Percent) : GateState;

// Assembly 2
public record class Locked : GateState; // ERROR - 'GateState' is a closed class

A consuming switch expression that covers all those derived classes can therefore be concluded to "exhaust" the closed class - it does not need to provide a default case to avoid warnings.

csharp
// Assembly 3
GateState state = ...;
string description = state switch
{
    Closed => "closed",
    Open(var percent) => $"{percent}% open"
    // No warning about missing cases
}; 

Design meetings

Related Proposals