A sealed class in C# is a class declared with theDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
sealed modifier, which explicitly prevents other classes from inheriting from it. When a class is marked as sealed, it terminates the inheritance hierarchy for that specific type, ensuring its implementation cannot be extended or modified through derivation.
Syntax and Behavior
To create a sealed class, place thesealed keyword before the class keyword in the declaration. Any attempt to derive from a sealed class results in a compile-time error (CS0509).
Technical Constraints and Characteristics
- Mutual Exclusivity with Abstract: A class cannot be both
sealedandabstract. Anabstractclass is designed specifically to be inherited and implemented, whereas asealedclass strictly forbids inheritance. Attempting to combine them yields compiler error CS0418. - Value Types: In the Common Type System (CTS), all value types (defined using the
structkeyword) are implicitly sealed. It is illegal to inherit from a struct, and therefore redundant (and invalid) to apply thesealedmodifier to one. - CLR Enforcement: At the Intermediate Language (IL) level, the C# compiler translates the keyword into the
sealedmetadata attribute. The Common Language Runtime (CLR) enforces this restriction during the type-loading phase, making it impossible to bypass even via reflection or by writing custom IL.
Sealed Members
Thesealed modifier can also be applied to methods, properties, indexers, or events. However, it is only valid on members that are overriding a virtual member from a base class.
Applying sealed to an overridden member allows the class itself to be inherited, but prevents any further derived classes from overriding that specific member.
sealed keyword must always be paired with the override keyword. It cannot be applied to standard virtual methods at their point of initial declaration, nor can it be applied to non-virtual members, as non-virtual members are implicitly incapable of being overridden.
Master C# with Deep Grasping Methodology!Learn More





