I need a collection class in C # that fires an event when I add or remove an item. Is there such a collection class?
ObservableCollection<T>should work in most cases. It implements INotifyCollectionChanged, which is an interface that:
ObservableCollection<T>
INotifyCollectionChanged
Notifies listeners of dynamic changes, for example, when items are added and removed, or the entire list is updated.
You can take a look at the class ObservableCollection, it has events for CollectionChanged, which handles when an item is added, deleted, changed, moved or the entire list is updated.
ObservableCollection
CollectionChanged
System.Collections.ObjectModel.ObservableCollection INotifyCollectionChanged, , , . , .NET 4 WPF.
You can always implement it INotifyCollectionChangedyourself.
In addition ObervableCollection, there is a second possible candidate BindingList<T>.
ObervableCollection
BindingList<T>