C#C
C#3y ago
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; }
    }

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

Is there a way to make the setter private?
Was this page helpful?