© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
12 replies
blokyk

✅ Override (abstract) getter-only property with a setter

Hello! I was wondering if there is anyway to add a setter to an overridden getter-only property?

Currently, I've tried the following:
public class Base {
    public abstract int Count { get; }
}

public class Derived : Base {
    // #1
    public override int Count { get; set; } // CS0546: Cannot override because no 'set' accessor

    // #2
    // CS0106: The 'override' modifier is not valid for this item
    // CS0538: 'Base' in explicit implementation is not an interface
    override Base.Count => Count;
    public new int Count { get; set; }
}
public class Base {
    public abstract int Count { get; }
}

public class Derived : Base {
    // #1
    public override int Count { get; set; } // CS0546: Cannot override because no 'set' accessor

    // #2
    // CS0106: The 'override' modifier is not valid for this item
    // CS0538: 'Base' in explicit implementation is not an interface
    override Base.Count => Count;
    public new int Count { get; set; }
}


I'd prefer avoiding a constructor, since the rest of my hierarchy uses
required
required
properties, and
Derived
Derived
is actually sub-classed elsewhere, so adding a constructor would make things a bit clunky...
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Static property override
C#CC# / help
2y ago
Property setter disappears on `PublishTrimmed`
C#CC# / help
11mo ago
❔ Question about getter property of list
C#CC# / help
3y ago
✅ How to change of property without setter?
C#CC# / help
3y ago