A sealed property in C# is a class or interface member that prevents derived types from overriding its implementation. In the context of class inheritance, it terminates the virtual dispatch chain for an overridden property. In the context of interfaces (introduced in C# 8.0), it locks a default property implementation, preventing derived interfaces or implementing types from providing their own explicit implementation.Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Syntax and Declaration
The syntax differs depending on whether the property is declared within a class or an interface. Class Declaration: In a class, thesealed keyword must be paired with the override modifier.
sealed keyword is applied directly to a property that provides a default implementation, without the override modifier.
Technical Constraints and Rules
- Class Context (Requires Override): Within a
class, a property can only be sealed if it is actively overriding avirtual,abstract, or previously overridden property from a base class. You cannot declare a new property assealedin a class, nor can you seal avirtualproperty at the point of its initial declaration. - Interface Context (Default Implementations): Within an
interface, a property can be declared assealedat its initial declaration, provided it includes a default implementation (a body). This prevents implementing classes or structs from explicitly redefining the property for that interface. - Compile-Time Enforcement:
- In classes, if a derived class attempts to use the
overridekeyword on a sealed property, the compiler throws error CS0239. - In interfaces, if a type implementing the interface attempts to provide an explicit interface implementation for the sealed property, the compiler throws error CS8704. If the type defines a public property with the exact same signature, the compiler simply ignores it during interface mapping. Because Default Interface Members (DIMs) are never inherited into the implementing class’s public API, the class property is treated as a completely independent member. It does not hide or shadow the interface member, and the compiler does not emit a hiding warning (CS0108).
- In classes, if a derived class attempts to use the
- Property-Level Application: The
sealedmodifier applies to the property as a single unit. You cannot seal an individualgetorsetaccessor independently; both accessors share the sealed state of the property. - Hiding via
new: While a derived type cannot override a sealed class property, it can hide it using thenewkeyword (public new DataType PropertyName). This creates a completely separate property that does not participate in the original polymorphic chain.
Code Visualization
The following examples demonstrate the compiler behavior of sealed properties in both classes and interfaces: 1. Sealed Properties in ClassesMaster C# with Deep Grasping Methodology!Learn More





