> ## 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.

# C# Sealed Property

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.

## Syntax and Declaration

The syntax differs depending on whether the property is declared within a class or an interface.

**Class Declaration:**
In a class, the `sealed` keyword must be paired with the `override` modifier.

```csharp theme={"dark"}
public sealed override DataType PropertyName { get; set; }
```

**Interface Declaration (C# 8.0+):**
In an interface, the `sealed` keyword is applied directly to a property that provides a default implementation, without the `override` modifier.

```csharp theme={"dark"}
sealed DataType PropertyName { get => defaultValue; }
```

## Technical Constraints and Rules

1. **Class Context (Requires Override):** Within a `class`, a property can only be sealed if it is actively overriding a `virtual`, `abstract`, or previously overridden property from a base class. You cannot declare a new property as `sealed` in a class, nor can you seal a `virtual` property at the point of its initial declaration.
2. **Interface Context (Default Implementations):** Within an `interface`, a property can be declared as `sealed` at 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.
3. **Compile-Time Enforcement:**
   * In classes, if a derived class attempts to use the `override` keyword 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).
4. **Property-Level Application:** The `sealed` modifier applies to the property as a single unit. You cannot seal an individual `get` or `set` accessor independently; both accessors share the sealed state of the property.
5. **Hiding via `new`:** While a derived type cannot override a sealed class property, it can hide it using the `new` keyword (`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 Classes**

```csharp theme={"dark"}
public class BaseEntity
{
    public virtual string Identifier { get; set; }
}

public class IntermediateEntity : BaseEntity
{
    // Overriding and sealing the property
    public sealed override string Identifier 
    { 
        get => base.Identifier; 
        set => base.Identifier = value; 
    }
}

public class LeafEntity : IntermediateEntity
{
    // COMPILE-TIME ERROR CS0239: 
    // 'LeafEntity.Identifier': cannot override inherited member 'IntermediateEntity.Identifier' because it is sealed.
    /*
    public override string Identifier 
    { 
        get => "New ID"; 
        set { }
    }
    */

    // Valid: Hiding the sealed property instead of overriding
    public new string Identifier { get; set; }
}
```

**2. Sealed Properties in Interfaces (C# 8.0+)**

```csharp theme={"dark"}
public interface IEntity
{
    // Sealing a default interface property implementation
    sealed string EntityType => "Standard";
}

public class ConcreteEntity : IEntity
{
    // COMPILE-TIME ERROR CS8704: 
    // 'ConcreteEntity' cannot implement interface member 'IEntity.EntityType' because it is sealed.
    /*
    string IEntity.EntityType => "Custom";
    */

    // Valid: This creates a completely independent property. 
    // Because default interface members are not inherited into the class's public API, 
    // this does not hide or shadow the interface member, and no CS0108 warning is emitted.
    public string EntityType => "Custom";
}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C# Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
