I have lots of entities with nested List<> in each.
For example, I have BaseEntity which has List<ColumnEntity>.
ColumnEntity class has List<Info> and so on.
We are working with a WPF UI, and we need to track all changes in every List of BaseEntity. It is implemented by instantiating a new ObservableCollection based on the needed list, and with binding to that ObservableCollection.
What are the pros and cons changing all these nested Lists to ObservableCollections? So we can track all changes in BaseEntity itself without reassigning each list of BaseEntity to modified bound ObservableCollection?
Assuming that methods specific to List are never used.
Interesting question, considering that both
ListandObservableCollectionimplementIList<T>there isn’t much of a difference there,ObservableCollectionalso implementsINotifyCollectionChangedinterface, which allows WPF to bind to it.One of the main differences is that
ObservableCollectiondoes not haveAddRangemethod, which might have some implications.Also, I would not use
ObservableCollectionfor places where I know I would not be binding to, for this reason, it is important to go over your design and make sure that you are taking the correct approach in separating layers of concern.As far as the differences between
Collection<T>andList<T>you can have a look hereGeneric Lists vs Collection