> ## 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# Override Property

An overridden property in C# allows a derived class to replace or extend the implementation of a property inherited from a base class. To enable this mechanism, the base class property must be explicitly marked with the `virtual`, `abstract`, or `override` modifier, and the derived class must declare the property using the `override` keyword with an identical signature.

```csharp theme={"dark"}
public abstract class BaseEntity
{
    // Virtual property: provides a default implementation
    public virtual int StatusLevel { get; set; }

    // Abstract property: defines the signature, forces implementation in derived class
    public abstract string Identifier { get; }
}

public class SpecificEntity : BaseEntity
{
    // Overriding a virtual property
    public override int StatusLevel
    {
        get => base.StatusLevel; 
        set => base.StatusLevel = value; 
    }

    // Overriding an abstract property (read-only)
    public override string Identifier => "Entity-123";
}
```

## Compiler Rules and Constraints

To successfully override a property, the C# compiler enforces strict structural rules:

* **Signature Matching:** The overriding property must have the exact same name and data type as the inherited base property.
* **Modifier Prerequisites:** You cannot override a standard (non-virtual) property. The base property must be `virtual`, `abstract`, or an already overridden property (`override`). It cannot be `static`.
* **Accessibility Parity:** The access modifier of the overriding property must exactly match the base property (e.g., a `protected virtual` property must be overridden as `protected override`).
* **Accessor Limitations:** A derived class cannot add new accessors. If the base property is read-only (only has a `get` accessor), the overriding property cannot introduce a `set` accessor.
* **Asymmetric Accessor Modifiers:** If the base property defines different access levels for its accessors (e.g., a `public` property with a `protected set`), the overriding accessors implicitly inherit those exact accessibility levels. You must omit the access modifier in the derived class (e.g., writing `set { ... }`). Explicitly applying an access modifier to an overridden accessor results in compiler error **CS0275** (`accessibility modifiers may not be used on accessors in an override`).

```csharp theme={"dark"}
public class BaseClass
{
    public virtual int Value { get; protected set; }
}

public class DerivedClass : BaseClass
{
    public override int Value 
    { 
        get => base.Value; 
        // The 'set' implicitly remains 'protected'. 
        // Writing 'protected set' here causes CS0275.
        set => base.Value = value; 
    }
}
```

## Accessing the Base Implementation

When overriding a `virtual` property, the derived class can invoke the parent class's property accessors using the `base` keyword. This is strictly used to extend, rather than completely replace, the base logic. Abstract properties do not have a base implementation to call.

```csharp theme={"dark"}
public override int StatusLevel
{
    get 
    {
        // Invokes the parent class's get accessor
        return base.StatusLevel; 
    }
    set 
    {
        // Invokes the parent class's set accessor
        base.StatusLevel = value; 
    }
}
```

## Sealing an Overridden Property

If a property is overridden, it remains virtual to any further derived classes. To terminate the inheritance chain and prevent deeper subclasses from overriding the property again, apply the `sealed` modifier alongside `override`.

```csharp theme={"dark"}
public sealed override int StatusLevel { get; set; }
```

## Covariant Return Types (C# 9.0+)

Starting with C# 9.0, overridden read-only properties support covariant return types. This means the overriding property can declare a return type that is more derived (more specific) than the return type declared in the base property.

```csharp theme={"dark"}
public abstract class BaseFactory
{
    public abstract BaseEntity Product { get; }
}

public class SpecificFactory : BaseFactory
{
    // Valid in C# 9.0+: SpecificEntity derives from BaseEntity
    public override SpecificEntity Product => new SpecificEntity(); 
}
```

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