I have a Products:List<Product> class.
I’d like to make it so that every time that I remove an item from that list, my program decreases a counter.
Is there a way to do it without overriding the Remove method or decreasing it manually? And if there is none, anybody knows where I can find the code for the Remove method?
Thanks!
I thought about associating the Remove method to an event, but I don’t know how to do it without overriding it or creating another method with the Remove method and the event inside it. Excuse me for my ignorance, but I’m just getting into OOP programming.
You could use an
ObservableCollection<Product>. It is inSystem.Collections.ObjectModelIt will fire an event when the collection changed. The arguments of the event will tell you if it is an removal, an addition etc.