© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
40 replies
LeMixer

✅ Make set accessor of inherited prop private

I have the following interface:
public interface IItemModel
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string ImageUrl { get; set; }
    }
public interface IItemModel
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string ImageUrl { get; set; }
    }

since methods in an interface can not be private, but I want the setter to be private I get
CS0277
CS0277
when trying this:
internal class FoodItemModel : IItemModel
    {
        public int Id { get; private set; }
    }
internal class FoodItemModel : IItemModel
    {
        public int Id { get; private set; }
    }

Is there a way to make the setter private?
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

✅ List of inherited objects
C#CC# / help
3y ago
Simplifying creation of inherited classes
C#CC# / help
3y ago
Cannot set readonly field in inherited constructor [Answered]
C#CC# / help
4y ago
How to set Object from Inherited class with Reflections
C#CC# / help
2y ago